Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions regression-tests/horn-contracts/Answers
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,19 @@ Inferred ACSL annotations
================================================================================

SAFE

stackptr-ilp32.hcc
Warning: The following clause has different terms with the same name (term: globalf1_0p:12)
main10_5(@h, globalf1_0p:12, c:9.\as[signed bv[32]]) :- c:9 >= -2147483648 & 2147483647 >= c:9 & globalf1_0p:12 >= -2147483648 & 2147483647 >= globalf1_0p:12 & @h = emptyHeap & globalf1_0p:12 = 0.\as[signed bv[32]].


Inferred ACSL annotations
================================================================================
/* contract for f1 */
/*@
requires \valid(p) && 2147483647 >= *p && *p >= -2147483648;
ensures \valid(p) && (*p == 0 || \old(*p) >= 2147483648 || -2147483649 >= \old(*p));
*/
================================================================================

SAFE
9 changes: 8 additions & 1 deletion regression-tests/horn-contracts/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ for name in $TESTS; do
echo
echo $name
$LAZABS -cex -acsl -m:entryPoint "$@" $name 2>&1 | grep -v 'at '
done
done

ILP32TESTS="stackptr-ilp32.hcc"
for name in $ILP32TESTS; do
echo
echo $name
$LAZABS -cex -acsl -arithMode:ilp32 "$@" $name 2>&1 | grep -v 'at '
done
12 changes: 12 additions & 0 deletions regression-tests/horn-contracts/stackptr-ilp32.hcc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*@contract@*/
static void f1(int *p)
{
*p = 0;
}

void main()
{
int c;
f1(&c);
assert(c == 0);
}
3 changes: 3 additions & 0 deletions regression-tests/horn-hcc-array/Answers
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,6 @@ SAFE

nondet-static-array-opt-3.c
SAFE

ilp32-bug-1.c
SAFE
9 changes: 9 additions & 0 deletions regression-tests/horn-hcc-array/ilp32-bug-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
int i[2];

void f1() {
assert(i[1] == (i[1] & 0x0000FFFF) + (i[1] & 0xFFFF0000));
}

void main() {
f1();
}
8 changes: 8 additions & 0 deletions regression-tests/horn-hcc-array/runtests
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ NONDETINITESTS="\
nondet-global-array-opt-1.c nondet-global-array-opt-2.c nondet-global-array-opt-3.c \
nondet-static-array-opt-1.c nondet-static-array-opt-2.c nondet-static-array-opt-3.c"

ILP32TESTS="ilp32-bug-1.c"

## -heapModel:native

for name in $TESTS; do
Expand Down Expand Up @@ -46,6 +48,12 @@ for name in $NONDETINITESTS; do
$LAZABS -cex -abstract:off -forceNondetInit -heapModel:native "$@" $name 2>&1 | grep -v 'at '
done

for name in $ILP32TESTS; do
echo
echo $name
$LAZABS -cex -abstract:off -forceNondetInit -heapModel:native -arithMode:ilp32 "$@" $name 2>&1 | grep -v 'at '
done

## -heapModel:array

# for name in $TESTS; do
Expand Down
24 changes: 17 additions & 7 deletions src/main/scala/tricera/concurrency/CCReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,21 @@ class CCReader private (prog : Program,
}).toList

// todo: only add types that exist in the program - should also add machine arithmetic types
val predefSignatures =
List(("O_Int", HeapObj.CtorSignature(List(("getInt", HeapObj.OtherSort(Sort.Integer))), ObjSort)),
("O_UInt", HeapObj.CtorSignature(List(("getUInt", HeapObj.OtherSort(Sort.Nat))), ObjSort)),
("O_Addr", HeapObj.CtorSignature(List(("getAddr", HeapObj.AddrSort)), ObjSort)),
("O_AddrRange", HeapObj.CtorSignature(List(("getAddrRange", HeapObj.AddrRangeSort)), ObjSort))
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following is an improvement, but still not ideal. Ideally, we collect which program types can be on the heap, and use only those types in predefSignatures.

val predefSignatures = List(
("O_Int", HeapObj.CtorSignature(
List(("getInt", HeapObj.OtherSort(CCInt.toSort))), ObjSort)),
("O_UInt", HeapObj.CtorSignature(
List(("getUInt", HeapObj.OtherSort(CCUInt.toSort))), ObjSort)),
("O_Addr", HeapObj.CtorSignature(
List(("getAddr", HeapObj.AddrSort)), ObjSort)),
("O_AddrRange", HeapObj.CtorSignature(
List(("getAddrRange", HeapObj.AddrRangeSort)), ObjSort))
)
// Make sure that we have one object sort per sort
private val ctorObjSorts =
predefSignatures.flatMap(s => s._2.arguments.map(_._2))
assert(ctorObjSorts.toSet.size == ctorObjSorts.size)


val wrapperSignatures : List[(String, HeapObj.CtorSignature)] =
predefSignatures ++
Expand Down Expand Up @@ -668,7 +677,8 @@ class CCReader private (prog : Program,
val structSels = heap.userHeapSelectors.slice(structCtorsOffset+structCount,
structCtorsOffset+2*structCount)

val objectSorts : scala.IndexedSeq[Sort] = objectGetters.toIndexedSeq.map(f => f.resSort)
val objectSorts : scala.IndexedSeq[Sort] =
objectGetters.toIndexedSeq.map(f => f.resSort)
val sortGetterMap : Map[Sort, MonoSortedIFunction] =
objectSorts.zip(objectGetters).toMap
val sortWrapperMap : Map[Sort, MonoSortedIFunction] =
Expand Down
Loading