|
| 1 | +#include <assert.h> |
| 2 | +#include <stdlib.h> |
| 3 | + |
| 4 | +struct STRUCTNAME |
| 5 | +{ |
| 6 | + int data; |
| 7 | + struct STRUCTNAME *next; |
| 8 | +}; |
| 9 | + |
| 10 | +int main() |
| 11 | +{ |
| 12 | + __CPROVER_field_decl_local("field1", (_Bool)0); |
| 13 | + |
| 14 | + struct STRUCTNAME a; |
| 15 | + |
| 16 | + assert(__CPROVER_get_field(&a, "field1") == 0); |
| 17 | + assert(__CPROVER_get_field(&(a.data), "field1") == 0); |
| 18 | + assert(__CPROVER_get_field(&(a.next), "field1") == 0); |
| 19 | + // Expect a warning here. We return 0 as default value. |
| 20 | + assert(__CPROVER_get_field(a.next, "field1") == 0); |
| 21 | + // Expect a warning here. We return 0 as default value. |
| 22 | + assert(__CPROVER_get_field((*(a.next)).next, "field1") == 0); |
| 23 | + |
| 24 | + __CPROVER_set_field(&(a.data), "field1", 1); |
| 25 | + __CPROVER_set_field(&(a.next), "field1", 1); |
| 26 | + // Expect a warning here. We cannot set SM because it doesn't exist. |
| 27 | + __CPROVER_set_field(&((*(a.next)).data), "field1", 1); |
| 28 | + // Expect a warning here. We cannot set SM because it doesn't exist. |
| 29 | + __CPROVER_set_field(&((*(*(a.next)).next).data), "field1", 1); |
| 30 | + |
| 31 | + assert(__CPROVER_get_field(&a, "field1") == 1); |
| 32 | + assert(__CPROVER_get_field(&(a.data), "field1") == 1); |
| 33 | + assert(__CPROVER_get_field(&(a.next), "field1") == 1); |
| 34 | + // Expect a warning here. We return 0 as default value. |
| 35 | + assert(__CPROVER_get_field(a.next, "field1") == 0); |
| 36 | + // Expect a warning here. We return 0 as default value. |
| 37 | + assert(__CPROVER_get_field((*(a.next)).next, "field1") == 0); |
| 38 | + |
| 39 | + struct STRUCTNAME b; |
| 40 | + a.next = &b; |
| 41 | + |
| 42 | + assert(__CPROVER_get_field(&a, "field1") == 1); |
| 43 | + assert(__CPROVER_get_field(&(a.data), "field1") == 1); |
| 44 | + assert(__CPROVER_get_field(&(a.next), "field1") == 1); |
| 45 | + // No warning here. |
| 46 | + assert(__CPROVER_get_field(a.next, "field1") == 0); |
| 47 | + // Expect a warning here. We return 0 as default value. |
| 48 | + assert(__CPROVER_get_field((*(a.next)).next, "field1") == 0); |
| 49 | + |
| 50 | + // No warning here. |
| 51 | + __CPROVER_set_field(&((*(a.next)).data), "field1", 1); |
| 52 | + // Expect a warning here. We cannot set SM because it doesn't exist. |
| 53 | + __CPROVER_set_field(&((*(*(a.next)).next).data), "field1", 1); |
| 54 | + |
| 55 | + // No warning here. |
| 56 | + assert(__CPROVER_get_field(a.next, "field1") == 1); |
| 57 | + // Expect a warning here. We return 0 as default value. |
| 58 | + assert(__CPROVER_get_field((*(a.next)).next, "field1") == 0); |
| 59 | + |
| 60 | + struct STRUCTNAME c; |
| 61 | + b.next = &c; |
| 62 | + // No warning here. |
| 63 | + assert(__CPROVER_get_field((*(a.next)).next, "field1") == 0); |
| 64 | + |
| 65 | + // No warning here. |
| 66 | + __CPROVER_set_field(&((*(*(a.next)).next).data), "field1", 1); |
| 67 | + |
| 68 | + // No warning here. |
| 69 | + assert(__CPROVER_get_field((*(a.next)).next, "field1") == 1); |
| 70 | +} |
0 commit comments