|
| 1 | +#include <assert.h> |
| 2 | + |
| 3 | +struct STRUCTNAME |
| 4 | +{ |
| 5 | + int x1; |
| 6 | + int x2; |
| 7 | +}; |
| 8 | + |
| 9 | +int main() |
| 10 | +{ |
| 11 | + __CPROVER_field_decl_local("field1", (char)0); |
| 12 | + |
| 13 | + struct STRUCTNAME n, m; |
| 14 | + int *p, *q; |
| 15 | + |
| 16 | + // Goto-symex is expected to create a case split for dereferencing p and q. |
| 17 | + int choice; |
| 18 | + __CPROVER_assume(choice > 0); |
| 19 | + if(choice) |
| 20 | + { |
| 21 | + p = &m.x1; |
| 22 | + q = &m.x2; |
| 23 | + } |
| 24 | + else |
| 25 | + { |
| 26 | + p = &n.x1; |
| 27 | + q = &n.x2; |
| 28 | + } |
| 29 | + |
| 30 | + assert(__CPROVER_get_field(&m.x1, "field1") == 0); |
| 31 | + assert(__CPROVER_get_field(&m.x2, "field1") == 0); |
| 32 | + assert(__CPROVER_get_field(p, "field1") == 0); |
| 33 | + assert(__CPROVER_get_field(q, "field1") == 0); |
| 34 | + |
| 35 | + __CPROVER_set_field(&m.x1, "field1", 2); |
| 36 | + assert(__CPROVER_get_field(&m.x1, "field1") == 2); |
| 37 | + assert(__CPROVER_get_field(&m.x2, "field1") == 0); |
| 38 | + assert(__CPROVER_get_field(p, "field1") == 2); |
| 39 | + assert(__CPROVER_get_field(q, "field1") == 0); |
| 40 | + |
| 41 | + __CPROVER_set_field(&m.x2, "field1", 3); |
| 42 | + assert(__CPROVER_get_field(&m.x1, "field1") == 2); |
| 43 | + assert(__CPROVER_get_field(&m.x2, "field1") == 3); |
| 44 | + assert(__CPROVER_get_field(p, "field1") == 2); |
| 45 | + assert(__CPROVER_get_field(q, "field1") == 3); |
| 46 | + |
| 47 | + __CPROVER_set_field(p, "field1", 4); |
| 48 | + assert(__CPROVER_get_field(&m.x1, "field1") == 4); |
| 49 | + assert(__CPROVER_get_field(&m.x2, "field1") == 3); |
| 50 | + assert(__CPROVER_get_field(p, "field1") == 4); |
| 51 | + assert(__CPROVER_get_field(q, "field1") == 3); |
| 52 | + |
| 53 | + __CPROVER_set_field(q, "field1", 5); |
| 54 | + assert(__CPROVER_get_field(&m.x1, "field1") == 4); |
| 55 | + assert(__CPROVER_get_field(&m.x2, "field1") == 5); |
| 56 | + assert(__CPROVER_get_field(p, "field1") == 4); |
| 57 | + assert(__CPROVER_get_field(q, "field1") == 5); |
| 58 | + |
| 59 | + assert(__CPROVER_get_field(&n.x1, "field1") == 0); |
| 60 | + assert(__CPROVER_get_field(&n.x2, "field1") == 0); |
| 61 | +} |
0 commit comments