1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify %s void clang_analyzer_eval(int); #define UINT_MAX (~0U) #define INT_MAX (UINT_MAX & (UINT_MAX >> 1)) #define INT_MIN (-INT_MAX - 1) // Each of these adjusted ranges has an adjustment small enough to split the // solution range across an overflow boundary (Min for <, Max for >). // This corresponds to one set of branches in RangeConstraintManager. void smallAdjustmentGT (unsigned a) { if (a+2 > 1) clang_analyzer_eval(a < UINT_MAX-1); // expected-warning{{TRUE}} else clang_analyzer_eval(a == UINT_MAX-1 || a == UINT_MAX); // expected-warning{{TRUE}} } void smallAdjustmentGE (unsigned a) { if (a+2 >= 1) clang_analyzer_eval(a < UINT_MAX-1 || a == UINT_MAX); // expected-warning{{TRUE}} else clang_analyzer_eval(a == UINT_MAX-1); // expected-warning{{TRUE}} } void smallAdjustmentLT (unsigned a) { if (a+1 < 2) clang_analyzer_eval(a == 0 || a == UINT_MAX); // expected-warning{{TRUE}} } void smallAdjustmentLE (unsigned a) { if (a+1 <= 2) clang_analyzer_eval(a == 0 || a == 1 || a == UINT_MAX); // expected-warning{{TRUE}} } // Each of these adjusted ranges has an adjustment large enough to push the // comparison value over an overflow boundary (Min for <, Max for >). // This corresponds to one set of branches in RangeConstraintManager. void largeAdjustmentGT (unsigned a) { if (a-2 > UINT_MAX-1) clang_analyzer_eval(a == 1); // expected-warning{{TRUE}} else clang_analyzer_eval(a != 1); // expected-warning{{TRUE}} } void largeAdjustmentGE (unsigned a) { if (a-2 >= UINT_MAX-1) clang_analyzer_eval(a == 1 || a == 0); // expected-warning{{TRUE}} else clang_analyzer_eval(a > 1); // expected-warning{{TRUE}} } void largeAdjustmentLT (unsigned a) { if (a+2 < 1) clang_analyzer_eval(a == UINT_MAX-1); // expected-warning{{TRUE}} else clang_analyzer_eval(a != UINT_MAX-1); // expected-warning{{TRUE}} } void largeAdjustmentLE (unsigned a) { if (a+2 <= 1) clang_analyzer_eval(a == UINT_MAX-1 || a == UINT_MAX); // expected-warning{{TRUE}} else clang_analyzer_eval(a < UINT_MAX-1); // expected-warning{{TRUE}} } // Test the nine cases in RangeConstraintManager's pinning logic. // For out-of-range tautologies, it may be the negation that actually // triggers the case in question. void mixedComparisons1(signed char a) { // Case 1: The range is entirely below the symbol's range. int min = INT_MIN; clang_analyzer_eval((a - 2) >= (min + 5LL)); // expected-warning{{TRUE}} clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} } void mixedComparisons2(signed char a) { // Case 2: Only the lower end of the range is outside. clang_analyzer_eval((a - 5) < (-0x81LL)); // expected-warning{{UNKNOWN}} if ((a - 5) < (-0x81LL)) { clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} clang_analyzer_eval(a == 0x7F); // expected-warning{{FALSE}} clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} } } void mixedComparisons3(signed char a) { // Case 3: The entire symbol range is covered. clang_analyzer_eval((a - 0x200) < -0x100LL); // expected-warning{{TRUE}} clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} } void mixedComparisons4(signed char a) { // Case 4: The range wraps around, but the lower wrap is out-of-range. clang_analyzer_eval((a - 5) > 0LL); // expected-warning{{UNKNOWN}} if ((a - 5) > 0LL) { clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == -0x80); // expected-warning{{FALSE}} } } void mixedComparisons5(signed char a) { // Case 5: The range is inside and may or may not wrap. clang_analyzer_eval((a + 5) == 0LL); // expected-warning{{UNKNOWN}} if ((a + 5) == 0LL) { clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} clang_analyzer_eval(a == 0x7F); // expected-warning{{FALSE}} clang_analyzer_eval(a == -0x80); // expected-warning{{FALSE}} } else { clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} } } void mixedComparisons6(signed char a) { // Case 6: Only the upper end of the range is outside. clang_analyzer_eval((a + 5) > 0x81LL); // expected-warning{{UNKNOWN}} if ((a + 5) > 0x81LL) { clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == -0x80); // expected-warning{{FALSE}} } } void mixedComparisons7(signed char a) { // Case 7: The range wraps around but is entirely outside the symbol's range. int min = INT_MIN; clang_analyzer_eval((a + 2) >= (min + 5LL)); // expected-warning{{TRUE}} clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} } void mixedComparisons8(signed char a) { // Case 8: The range wraps, but the upper wrap is out of range. clang_analyzer_eval((a + 5) < 0LL); // expected-warning{{UNKNOWN}} if ((a + 5) < 0LL) { clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} clang_analyzer_eval(a == 0x7F); // expected-warning{{FALSE}} clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} } } void mixedComparisons9(signed char a) { // Case 9: The range is entirely above the symbol's range. int max = INT_MAX; clang_analyzer_eval((a + 2) <= (max - 5LL)); // expected-warning{{TRUE}} clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} } void mixedSignedness1(int a) { unsigned max = UINT_MAX; clang_analyzer_eval(a < max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) < max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) < max); // expected-warning{{UNKNOWN}} } void mixedSignedness2(int a) { unsigned max = UINT_MAX; clang_analyzer_eval(a <= max); // expected-warning{{TRUE}} clang_analyzer_eval((a + 2) <= max); // expected-warning{{TRUE}} clang_analyzer_eval((a + 2U) <= max); // expected-warning{{TRUE}} } void mixedSignedness3(unsigned a) { int max = INT_MAX; clang_analyzer_eval(a < max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) < max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) < max); // expected-warning{{UNKNOWN}} } void mixedSignedness4(unsigned a) { int max = INT_MAX; clang_analyzer_eval(a <= max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) <= max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) <= max); // expected-warning{{UNKNOWN}} } void mixedSignedness5(unsigned a) { int min = INT_MIN; clang_analyzer_eval(a < min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) < min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) < min); // expected-warning{{UNKNOWN}} } void mixedSignedness6(unsigned a) { int min = INT_MIN; clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} } void mixedSignedness7(unsigned a) { unsigned min = 0; clang_analyzer_eval(a < min); // expected-warning{{FALSE}} clang_analyzer_eval((a + 2) < min); // expected-warning{{FALSE}} clang_analyzer_eval((a + 2U) < min); // expected-warning{{FALSE}} } void mixedSignedness8(unsigned a) { unsigned min = 0; clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} } void mixedSignedness9(unsigned a) { int min = 0; clang_analyzer_eval(a < min); // expected-warning{{FALSE}} clang_analyzer_eval((a + 2) < min); // expected-warning{{FALSE}} clang_analyzer_eval((a + 2U) < min); // expected-warning{{FALSE}} } void mixedSignedness10(unsigned a) { int min = 0; clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} } void mixedSignedness11(int a) { int min = 0; clang_analyzer_eval(a < min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) < min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) < min); // expected-warning{{FALSE}} } void mixedSignedness12(int a) { int min = 0; clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} } void mixedSignedness13(int a) { unsigned max = INT_MAX; clang_analyzer_eval(a < max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) < max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) < max); // expected-warning{{UNKNOWN}} } void mixedSignedness14(int a) { unsigned max = INT_MAX; clang_analyzer_eval(a <= max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) <= max); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) <= max); // expected-warning{{UNKNOWN}} } void mixedSignedness15(int a) { unsigned min = INT_MIN; clang_analyzer_eval(a < min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) < min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) < min); // expected-warning{{UNKNOWN}} } void mixedSignedness16(int a) { unsigned min = INT_MIN; clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} } void mixedSignedness17(int a) { unsigned max = INT_MAX; if (a < max) return; clang_analyzer_eval(a < 0); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} clang_analyzer_eval(a == INT_MAX); // expected-warning{{UNKNOWN}} } void mixedSignedness18(int a) { if (a >= 0) return; clang_analyzer_eval(a < 0); // expected-warning{{TRUE}} clang_analyzer_eval(a == (unsigned)INT_MIN); // expected-warning{{UNKNOWN}} clang_analyzer_eval(a == UINT_MAX); // expected-warning{{UNKNOWN}} } |