143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -analyzer-constraints=range %s 243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose 343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rosevoid clang_analyzer_eval(int); 4ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 59e607dd1dff375b4fa33d923ed592dad3ad43d42Jordy Rose#define UINT_MAX (~0U) 61d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose#define INT_MAX (UINT_MAX & (UINT_MAX >> 1)) 71d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose#define INT_MIN (-INT_MAX - 1) 81d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 9ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 10ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose// Each of these adjusted ranges has an adjustment small enough to split the 11ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose// solution range across an overflow boundary (Min for <, Max for >). 12ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose// This corresponds to one set of branches in RangeConstraintManager. 13ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rosevoid smallAdjustmentGT (unsigned a) { 14ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose if (a+2 > 1) 1543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a < UINT_MAX-1); // expected-warning{{TRUE}} 1643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose else 1743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == UINT_MAX-1 || a == UINT_MAX); // expected-warning{{TRUE}} 18ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose} 19ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 20ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rosevoid smallAdjustmentGE (unsigned a) { 21ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose if (a+2 >= 1) 2243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a < UINT_MAX-1 || a == UINT_MAX); // expected-warning{{TRUE}} 2343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose else 2443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == UINT_MAX-1); // expected-warning{{TRUE}} 25ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose} 26ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 27ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rosevoid smallAdjustmentLT (unsigned a) { 28ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose if (a+1 < 2) 2943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0 || a == UINT_MAX); // expected-warning{{TRUE}} 30ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose} 31ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 32ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rosevoid smallAdjustmentLE (unsigned a) { 33ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose if (a+1 <= 2) 3443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0 || a == 1 || a == UINT_MAX); // expected-warning{{TRUE}} 35ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose} 36ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 37ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 38ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose// Each of these adjusted ranges has an adjustment large enough to push the 39ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose// comparison value over an overflow boundary (Min for <, Max for >). 40ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose// This corresponds to one set of branches in RangeConstraintManager. 41ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rosevoid largeAdjustmentGT (unsigned a) { 42ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose if (a-2 > UINT_MAX-1) 4343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 1); // expected-warning{{TRUE}} 4443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose else 4543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a != 1); // expected-warning{{TRUE}} 46ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose} 47ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 48ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rosevoid largeAdjustmentGE (unsigned a) { 49ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose if (a-2 >= UINT_MAX-1) 5043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 1 || a == 0); // expected-warning{{TRUE}} 5143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose else 5243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a > 1); // expected-warning{{TRUE}} 53ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose} 54ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 55ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rosevoid largeAdjustmentLT (unsigned a) { 56ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose if (a+2 < 1) 5743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == UINT_MAX-1); // expected-warning{{TRUE}} 5843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose else 5943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a != UINT_MAX-1); // expected-warning{{TRUE}} 60ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose} 61ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose 62ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rosevoid largeAdjustmentLE (unsigned a) { 63ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose if (a+2 <= 1) 6443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == UINT_MAX-1 || a == UINT_MAX); // expected-warning{{TRUE}} 6543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose else 6643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a < UINT_MAX-1); // expected-warning{{TRUE}} 67ba0f61cf5363f80e3241dc754235dfb246afe320Jordy Rose} 681d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 691d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 701d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose// Test the nine cases in RangeConstraintManager's pinning logic. 7143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose// For out-of-range tautologies, it may be the negation that actually 7243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose// triggers the case in question. 731d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rosevoid mixedComparisons1(signed char a) { 741d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose // Case 1: The range is entirely below the symbol's range. 751d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose int min = INT_MIN; 761d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 7743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval((a - 2) >= (min + 5LL)); // expected-warning{{TRUE}} 781d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 7943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} 8043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} 8143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} 821d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose} 831d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 841d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rosevoid mixedComparisons2(signed char a) { 851d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose // Case 2: Only the lower end of the range is outside. 8643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval((a - 5) < (-0x81LL)); // expected-warning{{UNKNOWN}} 8743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose 881d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose if ((a - 5) < (-0x81LL)) { 8943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} 9043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{FALSE}} 9143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} 921d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose } 931d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose} 941d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 951d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rosevoid mixedComparisons3(signed char a) { 961d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose // Case 3: The entire symbol range is covered. 9743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval((a - 0x200) < -0x100LL); // expected-warning{{TRUE}} 9843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose 9943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} 10043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} 10143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} 1021d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose} 1031d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 1041d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rosevoid mixedComparisons4(signed char a) { 1051d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose // Case 4: The range wraps around, but the lower wrap is out-of-range. 10643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval((a - 5) > 0LL); // expected-warning{{UNKNOWN}} 10743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose 1081d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose if ((a - 5) > 0LL) { 10943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} 11043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} 11143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{FALSE}} 1121d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose } 1131d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose} 1141d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 1151d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rosevoid mixedComparisons5(signed char a) { 11643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose // Case 5: The range is inside and may or may not wrap. 11743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval((a + 5) == 0LL); // expected-warning{{UNKNOWN}} 1181d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 11943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose if ((a + 5) == 0LL) { 12043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} 12143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{FALSE}} 12243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{FALSE}} 1231d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose } else { 12443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} 12543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} 12643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} 1271d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose } 1281d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose} 1291d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 1301d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rosevoid mixedComparisons6(signed char a) { 1311d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose // Case 6: Only the upper end of the range is outside. 13243d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval((a + 5) > 0x81LL); // expected-warning{{UNKNOWN}} 13343d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose 1341d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose if ((a + 5) > 0x81LL) { 13543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} 13643d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} 13743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{FALSE}} 1381d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose } 1391d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose} 1401d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 1411d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rosevoid mixedComparisons7(signed char a) { 1421d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose // Case 7: The range wraps around but is entirely outside the symbol's range. 1431d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose int min = INT_MIN; 1441d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 14543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval((a + 2) >= (min + 5LL)); // expected-warning{{TRUE}} 1461d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 14743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} 14843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} 14943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} 1501d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose} 1511d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 1521d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rosevoid mixedComparisons8(signed char a) { 1531d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose // Case 8: The range wraps, but the upper wrap is out of range. 15443d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval((a + 5) < 0LL); // expected-warning{{UNKNOWN}} 15543d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose 1561d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose if ((a + 5) < 0LL) { 15743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} 15843d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{FALSE}} 15943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} 1601d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose } 1611d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose} 1621d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 1631d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rosevoid mixedComparisons9(signed char a) { 1641d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose // Case 9: The range is entirely above the symbol's range. 1651d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose int max = INT_MAX; 1661d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 16743d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval((a + 2) <= (max - 5LL)); // expected-warning{{TRUE}} 1681d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose 16943d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0); // expected-warning{{UNKNOWN}} 17043d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == 0x7F); // expected-warning{{UNKNOWN}} 17143d9f0d4e9b88dcab473a359a7b5579c2a619b22Jordy Rose clang_analyzer_eval(a == -0x80); // expected-warning{{UNKNOWN}} 1721d8db493f86761df9470254a2ad572fc6abf1bf6Jordy Rose} 1734708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 1744708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 1754708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness1(int a) { 1764708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose unsigned max = UINT_MAX; 1774708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < max); // expected-warning{{UNKNOWN}} 1784708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) < max); // expected-warning{{UNKNOWN}} 1794708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) < max); // expected-warning{{UNKNOWN}} 1804708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 1814708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 1824708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness2(int a) { 1834708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose unsigned max = UINT_MAX; 1844708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a <= max); // expected-warning{{TRUE}} 1854708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) <= max); // expected-warning{{TRUE}} 1864708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) <= max); // expected-warning{{TRUE}} 1874708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 1884708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 1894708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness3(unsigned a) { 1904708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose int max = INT_MAX; 1914708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < max); // expected-warning{{UNKNOWN}} 1924708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) < max); // expected-warning{{UNKNOWN}} 1934708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) < max); // expected-warning{{UNKNOWN}} 1944708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 1954708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 1964708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness4(unsigned a) { 1974708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose int max = INT_MAX; 1984708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a <= max); // expected-warning{{UNKNOWN}} 1994708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) <= max); // expected-warning{{UNKNOWN}} 2004708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) <= max); // expected-warning{{UNKNOWN}} 2014708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2024708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2034708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness5(unsigned a) { 2044708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose int min = INT_MIN; 2054708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < min); // expected-warning{{UNKNOWN}} 2064708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) < min); // expected-warning{{UNKNOWN}} 2074708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) < min); // expected-warning{{UNKNOWN}} 2084708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2094708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2104708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness6(unsigned a) { 2114708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose int min = INT_MIN; 2124708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} 2134708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} 2144708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} 2154708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2164708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2174708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness7(unsigned a) { 2184708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose unsigned min = 0; 2194708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < min); // expected-warning{{FALSE}} 2204708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) < min); // expected-warning{{FALSE}} 2214708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) < min); // expected-warning{{FALSE}} 2224708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2234708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2244708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness8(unsigned a) { 2254708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose unsigned min = 0; 2264708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} 2274708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} 2284708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} 2294708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2304708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2314708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness9(unsigned a) { 2324708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose int min = 0; 2334708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < min); // expected-warning{{FALSE}} 2344708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) < min); // expected-warning{{FALSE}} 2354708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) < min); // expected-warning{{FALSE}} 2364708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2374708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2384708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness10(unsigned a) { 2394708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose int min = 0; 2404708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} 2414708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} 2424708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} 2434708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2444708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2454708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness11(int a) { 2464708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose int min = 0; 2474708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < min); // expected-warning{{UNKNOWN}} 2484708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) < min); // expected-warning{{UNKNOWN}} 2494708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) < min); // expected-warning{{FALSE}} 2504708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2514708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2524708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness12(int a) { 2534708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose int min = 0; 2544708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} 2554708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} 2564708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} 2574708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2584708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2594708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness13(int a) { 2604708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose unsigned max = INT_MAX; 2614708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < max); // expected-warning{{UNKNOWN}} 2624708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) < max); // expected-warning{{UNKNOWN}} 2634708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) < max); // expected-warning{{UNKNOWN}} 2644708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2654708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2664708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness14(int a) { 2674708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose unsigned max = INT_MAX; 2684708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a <= max); // expected-warning{{UNKNOWN}} 2694708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) <= max); // expected-warning{{UNKNOWN}} 2704708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) <= max); // expected-warning{{UNKNOWN}} 2714708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2724708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2734708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness15(int a) { 2744708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose unsigned min = INT_MIN; 2754708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < min); // expected-warning{{UNKNOWN}} 2764708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) < min); // expected-warning{{UNKNOWN}} 2774708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) < min); // expected-warning{{UNKNOWN}} 2784708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2794708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2804708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness16(int a) { 2814708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose unsigned min = INT_MIN; 2824708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a <= min); // expected-warning{{UNKNOWN}} 2834708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2) <= min); // expected-warning{{UNKNOWN}} 2844708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval((a + 2U) <= min); // expected-warning{{UNKNOWN}} 2854708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2864708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2874708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness17(int a) { 2884708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose unsigned max = INT_MAX; 2894708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose if (a < max) 2904708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose return; 2914708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2924708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < 0); // expected-warning{{UNKNOWN}} 2934708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a == 0); // expected-warning{{FALSE}} 2944708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a == INT_MAX); // expected-warning{{UNKNOWN}} 2954708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 2964708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 2974708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rosevoid mixedSignedness18(int a) { 2984708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose if (a >= 0) 2994708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose return; 3004708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose 3014708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a < 0); // expected-warning{{TRUE}} 3024708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a == (unsigned)INT_MIN); // expected-warning{{UNKNOWN}} 3034708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose clang_analyzer_eval(a == UINT_MAX); // expected-warning{{UNKNOWN}} 3044708b3dde86b06f40927ae9cf30a2de83949a8f2Jordan Rose} 305