|
| 1 | +#include <assert.h> |
| 2 | + |
| 3 | +static void noop() |
| 4 | +{ |
| 5 | +} |
| 6 | + |
| 7 | +int main(int argc, char **argv) |
| 8 | +{ |
| 9 | + __CPROVER_assume(argc == 5); |
| 10 | + |
| 11 | + int a = 2; |
| 12 | + int b = 1; |
| 13 | + int *ptr_to_a_or_b = argv[0][0] == '0' ? &a : &b; |
| 14 | + |
| 15 | + // Should work (guarded by assume): |
| 16 | + int *p1 = ptr_to_a_or_b; |
| 17 | + __CPROVER_assume(p1 != &a); |
| 18 | + int c1 = *p1; |
| 19 | + |
| 20 | + int *p2 = ptr_to_a_or_b; |
| 21 | + __CPROVER_assume(*p2 != 2); |
| 22 | + int c2 = *p2; |
| 23 | + |
| 24 | + // Should work (guarded by else): |
| 25 | + int c3 = 0; |
| 26 | + int *p3 = ptr_to_a_or_b; |
| 27 | + if(p3 == &a) |
| 28 | + { |
| 29 | + } |
| 30 | + else |
| 31 | + { |
| 32 | + c3 = *p3; |
| 33 | + } |
| 34 | + |
| 35 | + int c4 = 0; |
| 36 | + int *p4 = ptr_to_a_or_b; |
| 37 | + if(*p4 == 2) |
| 38 | + { |
| 39 | + } |
| 40 | + else |
| 41 | + { |
| 42 | + c4 = *p4; |
| 43 | + } |
| 44 | + |
| 45 | + // Should work (guarded by if): |
| 46 | + int c5 = 0; |
| 47 | + int *p5 = ptr_to_a_or_b; |
| 48 | + if(p5 != &a) |
| 49 | + { |
| 50 | + c5 = *p5; |
| 51 | + } |
| 52 | + |
| 53 | + int c6 = 0; |
| 54 | + int *p6 = ptr_to_a_or_b; |
| 55 | + if(*p6 != 2) |
| 56 | + { |
| 57 | + c6 = *p6; |
| 58 | + } |
| 59 | + |
| 60 | + // Should work (guarded by backward goto): |
| 61 | + int *p7 = ptr_to_a_or_b; |
| 62 | + goto check7; |
| 63 | + |
| 64 | +divide7: |
| 65 | + int c7 = *p7; |
| 66 | + goto end_test7; |
| 67 | + |
| 68 | +check7: |
| 69 | + __CPROVER_assume(p7 != &a); |
| 70 | + goto divide7; |
| 71 | + |
| 72 | +end_test7: |
| 73 | + |
| 74 | + int *p8 = ptr_to_a_or_b; |
| 75 | + goto check8; |
| 76 | + |
| 77 | +divide8: |
| 78 | + int c8 = *p8; |
| 79 | + goto end_test8; |
| 80 | + |
| 81 | +check8: |
| 82 | + __CPROVER_assume(*p8 != 2); |
| 83 | + goto divide8; |
| 84 | + |
| 85 | +end_test8: |
| 86 | + |
| 87 | + // Should work (guarded by confluence): |
| 88 | + int *p9 = ptr_to_a_or_b; |
| 89 | + if(argv[1][0] == '0') |
| 90 | + __CPROVER_assume(p9 != &a); |
| 91 | + else |
| 92 | + __CPROVER_assume(p9 != &a); |
| 93 | + int c9 = *p9; |
| 94 | + |
| 95 | + int *p10 = ptr_to_a_or_b; |
| 96 | + if(argv[2][0] == '0') |
| 97 | + __CPROVER_assume(*p10 != 2); |
| 98 | + else |
| 99 | + __CPROVER_assume(*p10 != 2); |
| 100 | + int c10 = *p10; |
| 101 | + |
| 102 | + // Should work (guarded by confluence): |
| 103 | + int *p11 = ptr_to_a_or_b; |
| 104 | + __CPROVER_assume(p11 != &a); |
| 105 | + int *ptr = p11; |
| 106 | + *ptr = 1; |
| 107 | + int c11 = *p11; |
| 108 | + |
| 109 | + int *p12 = ptr_to_a_or_b; |
| 110 | + __CPROVER_assume(*p12 != 2); |
| 111 | + int *ptr = p12; |
| 112 | + *ptr = 1; |
| 113 | + int c12 = *p12; |
| 114 | + |
| 115 | + // Should work (guarded by confluence): |
| 116 | + int *p13 = ptr_to_a_or_b; |
| 117 | + __CPROVER_assume(p13 != &a); |
| 118 | + noop(); |
| 119 | + int c13 = *p13; |
| 120 | + |
| 121 | + int *p14 = ptr_to_a_or_b; |
| 122 | + __CPROVER_assume(*p14 != 2); |
| 123 | + noop(); |
| 124 | + int c14 = *p14; |
| 125 | + |
| 126 | + // Shouldn't work (unsafe as only guarded on one branch): |
| 127 | + int *p15 = ptr_to_a_or_b; |
| 128 | + if(argv[3][0] == '0') |
| 129 | + __CPROVER_assume(p15 != &a); |
| 130 | + else |
| 131 | + { |
| 132 | + } |
| 133 | + int c15 = *p15; |
| 134 | + |
| 135 | + int *p16 = ptr_to_a_or_b; |
| 136 | + if(argv[4][0] == '0') |
| 137 | + __CPROVER_assume(*p16 != 2); |
| 138 | + else |
| 139 | + { |
| 140 | + } |
| 141 | + int c16 = *p16; |
| 142 | + |
| 143 | + assert(0); |
| 144 | +} |
0 commit comments