Pierre Gousseau | e961b44 | 2016-01-12 10:07:56 +0000 | [diff] [blame] | 1 | // This test checks that intersecting ranges does not cause 'system is over constrained' assertions in the case of eg: 32 bits unsigned integers getting their range from 64 bits signed integers. |
| 2 | // RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-store=region -verify %s |
| 3 | |
| 4 | void clang_analyzer_warnIfReached(); |
| 5 | |
| 6 | void f1(long foo) |
| 7 | { |
| 8 | unsigned index = -1; |
| 9 | if (index < foo) index = foo; |
| 10 | if (index + 1 == 0) // because of foo range, index is in range [0; UINT_MAX] |
| 11 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 12 | else |
| 13 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 14 | } |
| 15 | |
| 16 | void f2(unsigned long foo) |
| 17 | { |
| 18 | int index = -1; |
| 19 | if (index < foo) index = foo; // index equals ULONG_MAX |
| 20 | if (index + 1 == 0) |
| 21 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 22 | else |
| 23 | clang_analyzer_warnIfReached(); // no-warning |
| 24 | } |
| 25 | |
| 26 | void f3(unsigned long foo) |
| 27 | { |
| 28 | unsigned index = -1; |
| 29 | if (index < foo) index = foo; |
| 30 | if (index + 1 == 0) |
| 31 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 32 | else |
| 33 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 34 | } |
| 35 | |
| 36 | void f4(long foo) |
| 37 | { |
| 38 | int index = -1; |
| 39 | if (index < foo) index = foo; |
| 40 | if (index + 1 == 0) |
| 41 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 42 | else |
| 43 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 44 | } |
| 45 | |
| 46 | void f5(long foo) |
| 47 | { |
| 48 | unsigned index = -1; |
| 49 | if (index < foo) index = foo; |
| 50 | if (index == -1) |
| 51 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 52 | else |
| 53 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 54 | } |
| 55 | |
| 56 | void f6(long foo) |
| 57 | { |
| 58 | unsigned index = -1; |
| 59 | if (index < foo) index = foo; |
| 60 | if (index == -1) |
| 61 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 62 | else |
| 63 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 64 | } |
| 65 | |
| 66 | void f7(long foo) |
| 67 | { |
| 68 | unsigned index = -1; |
| 69 | if (index < foo) index = foo; |
| 70 | if (index - 1 == 0) // Was not reached prior fix. |
| 71 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 72 | else |
| 73 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 74 | } |
| 75 | |
Pierre Gousseau | bdd9da1 | 2016-01-12 10:40:45 +0000 | [diff] [blame] | 76 | void f8(long foo) |
| 77 | { |
| 78 | unsigned index = -1; |
| 79 | if (index < foo) index = foo; |
| 80 | if (index + 1L == 0L) |
| 81 | clang_analyzer_warnIfReached(); // no-warning |
| 82 | else |
| 83 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 84 | } |
| 85 | |
Pierre Gousseau | e961b44 | 2016-01-12 10:07:56 +0000 | [diff] [blame] | 86 | void f9(long foo) |
| 87 | { |
| 88 | unsigned index = -1; |
| 89 | if (index < foo) index = foo; |
| 90 | if (index - 1L == 0L) // Was not reached prior fix. |
| 91 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 92 | else |
| 93 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 94 | } |
| 95 | |
| 96 | void f10(long foo) |
| 97 | { |
| 98 | unsigned index = -1; |
| 99 | if (index < foo) index = foo; |
| 100 | if (index + 1 == 0L) |
| 101 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 102 | else |
| 103 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 104 | } |
| 105 | |
Pierre Gousseau | bdd9da1 | 2016-01-12 10:40:45 +0000 | [diff] [blame] | 106 | void f11(long foo) |
| 107 | { |
| 108 | unsigned index = -1; |
| 109 | if (index < foo) index = foo; |
| 110 | if (index + 1UL == 0L) |
| 111 | clang_analyzer_warnIfReached(); // no-warning |
| 112 | else |
| 113 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 114 | } |
| 115 | |
Pierre Gousseau | e961b44 | 2016-01-12 10:07:56 +0000 | [diff] [blame] | 116 | void f12(long foo) |
| 117 | { |
| 118 | unsigned index = -1; |
| 119 | if (index < foo) index = foo; |
| 120 | if (index - 1UL == 0L) // Was not reached prior fix. |
| 121 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 122 | else |
| 123 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 124 | } |
| 125 | |
Pierre Gousseau | bdd9da1 | 2016-01-12 10:40:45 +0000 | [diff] [blame] | 126 | void f13(int foo) |
| 127 | { |
| 128 | unsigned short index = -1; |
| 129 | if (index < foo) index = foo; |
| 130 | if (index + 1 == 0) |
| 131 | clang_analyzer_warnIfReached(); // no-warning |
| 132 | else |
| 133 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 134 | } |
| 135 | |
Pierre Gousseau | e961b44 | 2016-01-12 10:07:56 +0000 | [diff] [blame] | 136 | void f14(long foo) |
| 137 | { |
| 138 | unsigned index = -1; |
| 139 | if (index < foo) index = foo; |
| 140 | long bar = foo; |
| 141 | if (index + 1 == 0) |
| 142 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 143 | else |
| 144 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 145 | } |
| 146 | |
| 147 | void f15(long foo) |
| 148 | { |
| 149 | unsigned index = -1; |
| 150 | if (index < foo) index = foo; |
| 151 | unsigned int tmp = index + 1; |
| 152 | if (tmp == 0) |
| 153 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 154 | else |
| 155 | clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} |
| 156 | } |