Skip to content

Commit 9ee153e

Browse files
committed
Add support for VIP
This commit is a backwards compatible change to some tests to enable VIP by default in CN in an upcoming commit.
1 parent 24c5400 commit 9ee153e

File tree

13 files changed

+20
-11
lines changed

13 files changed

+20
-11
lines changed

src/example-archive/c-testsuite/working/00032.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ main()
2020
p = &arr[1];
2121
if(*(p--) != 3)
2222
return 1;
23-
if(*(p--) != 2)
23+
if(*p != 2)
2424
return 2;
2525

2626
p = &arr[0];

src/example-archive/simple-examples/working/cast_1.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Cast a pointer to an int, and back
2+
// In regular VIP, this does not require a copy_alloc_id but as implemented
3+
// currently in CN, it does.
24

35
#include <stdint.h> // For uintptr_t, intptr_t
46

@@ -12,7 +14,7 @@ int cast_1()
1214
uintptr_t ptr_as_int = (uintptr_t) ptr_original;
1315

1416
// Cast back to pointer
15-
int *ptr_restored = (int *)ptr_as_int;
17+
int *ptr_restored = __cerbvar_copy_alloc_id(ptr_as_int, &x);
1618

1719
// Dereference the pointer
1820
int ret = *ptr_restored;

src/example-archive/simple-examples/working/cast_2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int cast_2()
1818
if (ptr_as_int < ptr_as_int_copy) // Check for overflow
1919
{
2020
ptr_as_int_copy = ptr_as_int_copy - 1;
21-
int *ptr_restored = (int *)ptr_as_int_copy;
21+
int *ptr_restored = __cerbvar_copy_alloc_id(ptr_as_int_copy, &x);
2222

2323
int ret = *ptr_restored;
2424

src/example-archive/simple-examples/working/cast_3.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int cast_3()
1919
if (ptr_as_int < ptr_as_int_copy) // Check for overflow
2020
{
2121
ptr_as_int_copy = ptr_as_int_copy - OFFSET;
22-
int *ptr_restored = (int *)ptr_as_int_copy;
22+
int *ptr_restored = __cerbvar_copy_alloc_id(ptr_as_int_copy, &x);
2323

2424
int ret = *ptr_restored;
2525

src/example-archive/simple-examples/working/cast_4.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int cast_4(int *ptr_original)
1919
if (ptr_as_int < ptr_as_int_copy) // Check for overflow
2020
{
2121
ptr_as_int_copy = ptr_as_int_copy - OFFSET;
22-
int *ptr_restored = (int *)ptr_as_int_copy;
22+
int *ptr_restored = __cerbvar_copy_alloc_id(ptr_as_int_copy, ptr_original);
2323

2424
int ret = *ptr_restored;
2525

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
int a;
1+
int a[2];
22
void b() {
3-
int *c = &a;
3+
int *c = &a[1];
44
c -= 1;
55
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Derived from src/example-archive/c-testsuite/broken/error-proof/00032.err1.c
22

3-
int a;
3+
int a[2];
44
void b() {
5-
int *c = &a;
5+
int *c = &a[1];
66
--c;
77
}

src/examples/queue_cn_types_2.h

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ predicate (datatype seq) IntQueueFB (pointer front, pointer back) {
55
} else {
66
take B = Owned<struct int_queueCell>(back);
77
assert (is_null(B.next));
8+
assert (ptr_eq(front, back) || !addr_eq(front, back));
89
take L = IntQueueAux (front, back);
910
return snoc(L, B.first);
1011
}

src/examples/queue_cn_types_3.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ predicate (datatype seq) IntQueueAux (pointer f, pointer b) {
44
return Seq_Nil{};
55
} else {
66
take F = Owned<struct int_queueCell>(f);
7-
assert (!is_null(F.next));
7+
assert (!is_null(F.next));
8+
assert (ptr_eq(F.next, b) || !addr_eq(F.next, b));
89
take B = IntQueueAux(F.next, b);
910
return Seq_Cons{head: F.first, tail: B};
1011
}

src/examples/queue_pop.c

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ int IntQueue_pop (struct int_queue *q)
1212
/*@ split_case is_null(q->front); @*/
1313
struct int_queueCell* h = q->front;
1414
if (h == q->back) {
15+
/*@ assert ((alloc_id) h == (alloc_id) (q->back)); @*/
1516
int x = h->first;
1617
freeIntQueueCell(h);
1718
q->front = 0;

src/examples/queue_push.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void IntQueue_push (int x, struct int_queue *q)
1818
struct int_queueCell *oldback = q->back;
1919
q->back->next = c;
2020
q->back = c;
21-
/*@ apply push_lemma (q->front, oldback); @*/
21+
/*@ apply push_lemma(q->front, oldback); @*/
2222
return;
2323
}
2424
}

src/examples/queue_push_induction.c

+2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ void push_induction(struct int_queueCell* front
55
, struct int_queueCell* last)
66
/*@
77
requires
8+
ptr_eq(front, second_last) || !addr_eq(front, second_last);
89
take Q = IntQueueAux(front, second_last);
910
take Second_last = Owned(second_last);
1011
ptr_eq(Second_last.next, last);
1112
take Last = Owned(last);
1213
ensures
14+
ptr_eq(front, last) || !addr_eq(front, last);
1315
take NewQ = IntQueueAux(front, last);
1416
take Last2 = Owned(last);
1517
NewQ == snoc(Q, Second_last.first);

src/examples/queue_push_lemma.h

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/*@
22
lemma push_lemma (pointer front, pointer p)
33
requires
4+
ptr_eq(front, p) || !addr_eq(front, p);
45
take Q = IntQueueAux(front, p);
56
take P = Owned<struct int_queueCell>(p);
67
ensures
8+
ptr_eq(front, P.next) || !addr_eq(front, P.next);
79
take NewQ = IntQueueAux(front, P.next);
810
NewQ == snoc(Q, P.first);
911
@*/

0 commit comments

Comments
 (0)