Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theory of heaps translation (again) #13

Merged
merged 55 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0577ace
Add TheoryOfHeapProcessor and ContractConditionTools
OskarSoderberg May 3, 2023
62b6458
Add EqualityReader and IExpressionProcessor trait
OskarSoderberg May 4, 2023
aec33c9
Add PostconditionSimplifier
OskarSoderberg May 4, 2023
69e9a3e
Add ACSLExpressionProcessor and improve match readability
OskarSoderberg May 7, 2023
d860aba
Add EqualitySwapper
OskarSoderberg May 8, 2023
8d117c6
Add ClauseRemover
OskarSoderberg May 8, 2023
27a6df5
Add ACSLExpressions to ACSLLineariser
OskarSoderberg May 9, 2023
d17525b
Add ADTSimplifier and fix getter extraction in TOHProcessor
OskarSoderberg May 10, 2023
76bb29e
Add struct dereference translation
OskarSoderberg May 15, 2023
aa24644
Fix uniform expression processing
OskarSoderberg May 16, 2023
394b6ab
Replace IExpressionProcessor by ContractProcessor
OskarSoderberg May 16, 2023
aa636fc
Refactor ACSLExpressionProcessor
OskarSoderberg May 16, 2023
3663942
Refactor ADTSimplifier
OskarSoderberg May 16, 2023
7745649
Refactor classes with ContractProcessor
OskarSoderberg May 16, 2023
c3a95e6
Refactor TheoryOfHeapFunApp
OskarSoderberg May 16, 2023
ae50c3f
Move out AssignmentProcessor and fix TheoryOfHeapFunApp
OskarSoderberg May 16, 2023
0794c78
Replace Equalities by ValSet
OskarSoderberg May 16, 2023
17047cc
Refactor EqualitySwapper
OskarSoderberg May 17, 2023
01a89b7
Add HeapPropProcessor and remove PostconditionSimplifier from processors
OskarSoderberg May 17, 2023
c919d9d
Add separated and first write filtering to AssignmentProcessor
OskarSoderberg May 17, 2023
d0f2066
Add getClauses for Assignment- and PointerPropProcessor
OskarSoderberg May 18, 2023
83cc797
Add properties to ContractInfo
OskarSoderberg May 18, 2023
32cf7fe
Add PostconditionSimplifier again
OskarSoderberg May 18, 2023
82dd990
Add ExplicitPointerRemover and TrivialEqualityRemover
OskarSoderberg May 18, 2023
26ae945
Add general removal of explicit pointers
OskarSoderberg May 21, 2023
aeab155
Fix bug where an empty separatedSet would result in no assignments
OskarSoderberg May 21, 2023
e791d0f
Add false check for PostconditionSimplifier
OskarSoderberg May 23, 2023
99cc2d6
Fix bug where equalities within OR clauses were read
OskarSoderberg May 23, 2023
0d6972c
Fix bug where ExplPointerRemover missed pointers
OskarSoderberg May 23, 2023
0963b3e
Fix bug where quantifierDepth wasn't passed
OskarSoderberg May 23, 2023
5fe19fb
Fix bug where ExplicitPointerRemover missed last formula
OskarSoderberg May 24, 2023
a5ce42e
Add HeapEqualityRemover
OskarSoderberg May 24, 2023
b7c21dd
Remove is_O_<sort> to valid translation
OskarSoderberg May 24, 2023
2f09eae
Refactor getStructMap to val
OskarSoderberg May 24, 2023
9a101d2
Rename isCurrentHeap
OskarSoderberg May 24, 2023
548324d
Fix formula shift in EqualitySwapper and fix prints
OskarSoderberg May 30, 2023
267965f
Clean up main function
OskarSoderberg Oct 1, 2023
ca08a61
(WIP) Do not apply heap processor when there is no heap.
zafer-esen Oct 9, 2023
f457942
Fix heap processors running when no heap available
OskarSoderberg Oct 14, 2023
2aacdf7
Add preambles and high-level descriptions
OskarSoderberg Oct 14, 2023
f1917e7
Add -debug option for printing debug messages and clean up some debug…
zafer-esen Oct 18, 2023
19042b1
Update years in preambles and list of contributors
zafer-esen Oct 18, 2023
13f0ced
Fix build issues after rebase to master
May 24, 2024
30d17a0
Remove extraneous 'UNSAFE' printout
May 29, 2024
b9a3251
Draft regression tests for ACSL theory of heap translation
May 29, 2024
a78d299
Second draft regression tests for ACSL theory of heap translation
May 30, 2024
bbfbf9b
Add regression-tests/toh-contract-translation/runtests
May 30, 2024
3869799
Add regression tests to 'runalldirs'
May 31, 2024
be699b7
Removed unused files
May 31, 2024
971f955
Add regression-tests/toh-contract-translation/Answers
May 31, 2024
b081923
Correct projec/build.properties
May 31, 2024
a529938
Remove failing regression test from toh-contract-translation suite
Jun 12, 2024
481819f
Add changes from theory-of-heaps-translation-thesis-version
Jun 10, 2024
c6db602
Merge branch 'ola-theory-of-heaps-translation' of https://github.com/…
Jun 17, 2024
ed405fe
Use empty heap instead of quantified heap variable
Jun 19, 2024
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
1 change: 1 addition & 0 deletions regression-tests/runalldirs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ run_test ./rundir math-arrays "" -assert -dev -t:60
run_test ./rundir quantifiers "" -assert -dev -t:60
run_test ./rundir interpreted-predicates "" -assert -dev -t:60
run_test ./rundir properties "" -assert -dev -t:60
run_test ./rundir toh-contract-translation "" -dev -t:60
#run_test ./rundir ParametricEncoder ""

if [ $ERRORS -ne 0 ]; then
Expand Down
153 changes: 153 additions & 0 deletions regression-tests/toh-contract-translation/Answers
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@

get-1.c
Warning: no definition of function "non_det_int" available
Warning: no definition of function "non_det_int" available
Warning: no definition of function "non_det_int_ptr" available

Inferred ACSL annotations
================================================================================
/* contracts for get */
/*@
requires p == n && n_init >= 1;
ensures ((\result == 0 && 0 >= \old(*n)) || \result >= 0) && r1 == \old(r1) && n_init == \old(n_init) && \old(n) == n;
*/
================================================================================

SAFE

incdec-1.c
Warning: no definition of function "non_det_int" available
Warning: no definition of function "non_det_int" available
Warning: no definition of function "non_det_int_ptr" available
Warning: no definition of function "non_det_int_ptr" available

Inferred ACSL annotations
================================================================================
/* contracts for decrement */
/*@
requires \separated(a, b) && \valid(a) && \valid(b);
ensures a_init == \old(a_init) && b_init == \old(b_init) && a == \old(a) && b == \old(b) && \separated(a, b) && \valid(a) && \valid(b);
*/
/* contracts for increment */
/*@
requires val == a && \separated(val, b) && \valid(val) && \valid(b);
ensures \old(val) == a && a_init == \old(a_init) && b_init == \old(b_init) && \old(val) == \old(a) && b == \old(b) && \separated(val, b) && \valid(val) && \valid(b) && *val == 1 + \old(*val);
*/
================================================================================

SAFE

incdec-2.c
Warning: no definition of function "non_det_int" available
Warning: no definition of function "non_det_int_ptr" available

Inferred ACSL annotations
================================================================================
/* contracts for decrement */
/*@
requires \valid(a);
ensures a_init == \old(a_init) && a == \old(a) && \valid(a);
*/
/* contracts for increment */
/*@
requires val == a && \valid(val);
ensures \old(val) == a && a_init == \old(a_init) && \valid(val) && *val == 1 + \old(*val);
*/
================================================================================

SAFE

max-1.c
Warning: no definition of function "non_det_int" available
Warning: no definition of function "non_det_int_ptr" available
Warning: no definition of function "non_det_int_ptr" available
Warning: no definition of function "non_det_int" available
Warning: no definition of function "non_det_int" available

Inferred ACSL annotations
================================================================================
/* contracts for findMax */
/*@
requires x == a && y == b && \separated(x, y) && \valid(x) && \valid(y);
ensures ((a_init == \result && \result >= b_init) || (b_init - a_init >= 1 && b_init == \result)) && r == \old(r) && a_init == \old(a_init) && b_init == \old(b_init) && \old(a) == a && \old(b) == b;
*/
================================================================================

SAFE

max-2.c
Warning: no definition of function "non_det_int_ptr" available
Warning: no definition of function "non_det_int_ptr" available
Warning: no definition of function "non_det_int_ptr" available
Warning: no definition of function "non_det_int" available
Warning: no definition of function "non_det_int" available

Inferred ACSL annotations
================================================================================
/* contracts for findMax */
/*@
requires max == r && x == a && y == b && \separated(x, y) && \separated(x, max) && \separated(y, max) && \valid(x) && \valid(y) && \valid(max);
ensures (\old(b_init) - \old(a_init) >= 1 || \old(a_init) >= \old(b_init)) && a == \old(x) && b == \old(y) && r == \old(max) && \old(a_init) == a_init && \old(b_init) == b_init;
*/
================================================================================

SAFE

multadd-1.c
Warning: no definition of function "non_det_int_ptr" available
Warning: no definition of function "non_det_int_ptr" available
Warning: no definition of function "non_det_int_ptr" available
Warning: no definition of function "non_det_int" available
Warning: no definition of function "non_det_int" available
Warning: The following clause has different terms with the same name (term: b:12)
main_12(@h_post, a_post, b_post, result_post, a_init_post, b_init_post) :- main39_3(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13), addTwoNumbers_post(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13, @h_post, a_post, b_post, result_post, a_init_post, b_init_post).

Warning: The following clause has different terms with the same name (term: result:13)
main_12(@h_post, a_post, b_post, result_post, a_init_post, b_init_post) :- main39_3(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13), addTwoNumbers_post(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13, @h_post, a_post, b_post, result_post, a_init_post, b_init_post).

Warning: The following clause has different terms with the same name (term: a:11)
main_12(@h_post, a_post, b_post, result_post, a_init_post, b_init_post) :- main39_3(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13), addTwoNumbers_post(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13, @h_post, a_post, b_post, result_post, a_init_post, b_init_post).

Warning: The following clause has different terms with the same name (term: b:12)
addTwoNumbers_pre(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13) :- main39_3(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13).

Warning: The following clause has different terms with the same name (term: result:13)
addTwoNumbers_pre(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13) :- main39_3(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13).

Warning: The following clause has different terms with the same name (term: a:11)
addTwoNumbers_pre(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13) :- main39_3(@h, a:11, b:12, result:13, a_init:14, b_init:15, a:11, b:12, result:13).


Inferred ACSL annotations
================================================================================
/* contracts for addTwoNumbers */
/*@
requires \separated(a, b) && \separated(a, result) && \separated(b, result) && \valid(a) && \valid(b) && \valid(result);
ensures a == \old(a) && b == \old(b) && result == \old(result) && a_init == \old(a_init) && b_init == \old(b_init) && \separated(a, b) && \separated(a, result) && \separated(b, result) && \valid(a) && \valid(b) && \valid(result);
*/
/* contracts for multiplyByTwo */
/*@
requires num == a && \separated(num, b) && \separated(num, result) && \separated(b, result) && \valid(num) && \valid(b) && \valid(result);
ensures \old(num) == a && \old(num) == \old(a) && b == \old(b) && result == \old(result) && a_init == \old(a_init) && b_init == \old(b_init) && \separated(num, b) && \separated(num, result) && \separated(b, result) && \valid(num) && \valid(b) && \valid(result) && *num == 2*\old(*num);
*/
================================================================================

SAFE

truck-2.c

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Init:
main21_1(emptyHeap, 0, 0, 0, emptyHeap, 0, 0, 0)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
V
main46_22(newHeap(alloc(newHeap(alloc(newHeap(alloc(emptyHeap, O_Truck(Truck(5, nthAddr(3))))), O_Human(Human(2)))), O_Human(Human(3)))), 2, 3, 5, emptyHeap, 0, 0, 0, 1)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Final:
main46_22(newHeap(alloc(newHeap(alloc(newHeap(alloc(emptyHeap, O_Truck(Truck(5, nthAddr(3))))), O_Human(Human(2)))), O_Human(Human(3)))), 2, 3, 5, emptyHeap, 0, 0, 0, 1)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Failed assertion:

UNSAFE
34 changes: 34 additions & 0 deletions regression-tests/toh-contract-translation/get-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

int r1;
int n_init;

/*@contract@*/
int get(int* p) {
if (*p <= 0) {
return 0;
} else {
*p = *p - 1;
return 1 + get(p);
}
}

int* n;

extern int non_det_int();
extern int* non_det_int_ptr();

void main()
{
//Non-det assignment of global variables
r1 = non_det_int();
n_init = non_det_int();
n = non_det_int_ptr();

assume((n_init > 0));

n = (int*) malloc(sizeof(*n));
*n = n_init;
r1 = get(n);

assert(((r1 >= n_init) && (r1 <= n_init)));
}
42 changes: 42 additions & 0 deletions regression-tests/toh-contract-translation/get-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// TODO: This test currently results in
//
// java.lang.Exception: Predicate generation failed
// (error "Predicate generation failed")
// Other Error: Predicate generation failed
//
//
int r1;
int n_init;


int get(int* p) {
if (*p <= 0) {
return 0;
} else {
*p = *p - 1;
return 1 + get(p);
}
}

int* n;

extern int non_det_int();
extern int* non_det_int_ptr();

void main()
{
//Non-det assignment of global variables
r1 = non_det_int();
n_init = non_det_int();
n = non_det_int_ptr();

assume((n_init > 0));

n = (int*) malloc(sizeof(*n));
// Commenting out the following line makes the test pass,
// but leads to undefined behavior.
*n = n_init;
r1 = get(n);

assert(((r1 >= n_init) && (r1 <= (n_init * n_init))));
}
40 changes: 40 additions & 0 deletions regression-tests/toh-contract-translation/incdec-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
int a_init;
int b_init;

/*@contract@*/
void increment(int* val) {
(*val)++;
}

/*@contract@*/
void decrement(int* val) {
(*val)--;
}

int *a;
int *b;

extern int non_det_int();
extern int* non_det_int_ptr();

void main()
{
//Non-det assignment of global variables
a_init = non_det_int();
b_init = non_det_int();
a = non_det_int_ptr();
b = non_det_int_ptr();

assume(1);

a = (int*) malloc(sizeof(*a));
b = (int*) malloc(sizeof(*b));

*a = a_init;
*b = b_init;

increment(a);
decrement(b);

assert(((*a == (a_init + 1)) && (*b == (b_init - 1))));
}
34 changes: 34 additions & 0 deletions regression-tests/toh-contract-translation/incdec-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
int a_init;

/*@contract@*/
void increment(int* val) {
(*val)++;
}

/*@contract@*/
void decrement(int* val) {
(*val)--;
}

int *a;

extern int non_det_int();
extern int* non_det_int_ptr();

void main()
{
//Non-det assignment of global variables
a_init = non_det_int();
a = non_det_int_ptr();

assume(1);

a = (int*) malloc(sizeof(*a));

*a = a_init;

increment(a);
decrement(a);

assert((*a == a_init));
}
37 changes: 37 additions & 0 deletions regression-tests/toh-contract-translation/incdec-3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
int a_init;
int b_init;

/*@contract@*/
void increment(int* val) {
(*val)++;
}

/*@contract@*/
void decrement(int* val) {
increment(val);
*val = *val - 2;
}

int *a;

extern int non_det_int();
extern int* non_det_int_ptr();

void main()
{
//Non-det assignment of global variables
a_init = non_det_int();
b_init = non_det_int();
a = non_det_int_ptr();

assume(1);

a = (int*) malloc(sizeof(*a));

*a = a_init;

increment(a);
decrement(a);

assert((*a == a_init));
}
40 changes: 40 additions & 0 deletions regression-tests/toh-contract-translation/max-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
int r;

/*@contract@*/
int findMax(int* x, int* y) {
if(*x >= *y)
return *x;
else
return *y;
}

int* a;
int* b;
int a_init;
int b_init;

extern int non_det_int();
extern int* non_det_int_ptr();

void main()
{
//Non-det assignment of global variables
r = non_det_int();
a = non_det_int_ptr();
b = non_det_int_ptr();
a_init = non_det_int();
b_init = non_det_int();

assume(1);

a = (int*) malloc(sizeof(*a));
b = (int*) malloc(sizeof(*b));

*a = a_init;
*b = b_init;

r = findMax(a, b);

assert(!((a_init >= b_init) && !(r == a_init)));
assert(!((b_init > a_init) && !(r == b_init)));
}
Loading
Loading