|
| 1 | +#include <assert.h> |
| 2 | + |
| 3 | +static void noop() { } |
| 4 | + |
| 5 | +int test(int nondet_int) { |
| 6 | + int a = 1, b = 2, c = 3; |
| 7 | + |
| 8 | + // Symex knows the value of ptr_to_a, so it should be able to evaluate simple |
| 9 | + // conditions involving it. |
| 10 | + int *ptr_to_a = &a; |
| 11 | + |
| 12 | + int unconditionally_reachable_1; |
| 13 | + if(ptr_to_a == &a) |
| 14 | + unconditionally_reachable_1 = 7; |
| 15 | + |
| 16 | + int unreachable_2; |
| 17 | + if(ptr_to_a == &c) |
| 18 | + unreachable_2 = 7; |
| 19 | + |
| 20 | + int unconditionally_reachable_3; |
| 21 | + if(ptr_to_a != &c) |
| 22 | + unconditionally_reachable_3 = 7; |
| 23 | + |
| 24 | + int unreachable_4; |
| 25 | + if(ptr_to_a != &a) |
| 26 | + unreachable_4 = 7; |
| 27 | + |
| 28 | + // Symex can't tell what ptr_to_a_or_b points to, but we can tell that it |
| 29 | + // doesn't point to some things |
| 30 | + int *ptr_to_a_or_b = nondet_int == 0 ? &a : &b; |
| 31 | + |
| 32 | + int possibly_reachable_5; |
| 33 | + if(ptr_to_a_or_b == &a) |
| 34 | + possibly_reachable_5 = 7; |
| 35 | + |
| 36 | + int unreachable_6; |
| 37 | + if(ptr_to_a_or_b == &c) |
| 38 | + unreachable_6 = 7; |
| 39 | + |
| 40 | + int unconditionally_reachable_7; |
| 41 | + if(ptr_to_a_or_b != &c) |
| 42 | + unconditionally_reachable_7 = 7; |
| 43 | + |
| 44 | + int possibly_reachable_8; |
| 45 | + if(ptr_to_a_or_b != &a) |
| 46 | + possibly_reachable_8 = 7; |
| 47 | + |
| 48 | + // We should also be able to do all of the above in compound expressions which |
| 49 | + // use logical operators like AND, OR and NOT. |
| 50 | + |
| 51 | + int unconditionally_reachable_9; |
| 52 | + if(!(ptr_to_a == &c)) |
| 53 | + unconditionally_reachable_9 = 7; |
| 54 | + |
| 55 | + int unreachable_10; |
| 56 | + if(!(ptr_to_a == &a)) |
| 57 | + unreachable_10 = 7; |
| 58 | + |
| 59 | + int unconditionally_reachable_11; |
| 60 | + if(!(ptr_to_a_or_b == &c)) |
| 61 | + unconditionally_reachable_11 = 7; |
| 62 | + |
| 63 | + int possibly_reachable_12; |
| 64 | + if(!(ptr_to_a_or_b == &a)) |
| 65 | + possibly_reachable_12 = 7; |
| 66 | + |
| 67 | + int unconditionally_reachable_13; |
| 68 | + if((ptr_to_a == &a && c == 3) || c == 0) |
| 69 | + unconditionally_reachable_13 = 7; |
| 70 | + |
| 71 | + int unreachable_14; |
| 72 | + if((ptr_to_a_or_b == &c && c == 3) || c == 0) |
| 73 | + unreachable_14 = 7; |
| 74 | + |
| 75 | + assert(0); |
| 76 | +} |
0 commit comments