diff options
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/Analysis/additive-folding.cpp | 6 | ||||
-rw-r--r-- | clang/test/Sema/compare.c | 32 | ||||
-rw-r--r-- | clang/test/Sema/outof-range-constant-compare.c | 149 | ||||
-rw-r--r-- | clang/test/SemaCXX/compare.cpp | 32 | ||||
-rw-r--r-- | clang/test/SemaCXX/for-range-examples.cpp | 8 | ||||
-rw-r--r-- | clang/test/SemaCXX/warn-enum-compare.cpp | 4 |
6 files changed, 190 insertions, 41 deletions
diff --git a/clang/test/Analysis/additive-folding.cpp b/clang/test/Analysis/additive-folding.cpp index 33f3b9b2517..7355a752469 100644 --- a/clang/test/Analysis/additive-folding.cpp +++ b/clang/test/Analysis/additive-folding.cpp @@ -128,10 +128,10 @@ void tautologies(unsigned a) { // Tautologies from outside the range of the symbol void tautologiesOutside(unsigned char a) { - clang_analyzer_eval(a <= 0x100); // expected-warning{{TRUE}} - clang_analyzer_eval(a < 0x100); // expected-warning{{TRUE}} + clang_analyzer_eval(a <= 0x100); // expected-warning{{comparison of literal 256 with expression of type 'unsigned char' is always true}} expected-warning{{TRUE}} + clang_analyzer_eval(a < 0x100); // expected-warning{{comparison of literal 256 with expression of type 'unsigned char' is always true}} expected-warning{{TRUE}} - clang_analyzer_eval(a != 0x100); // expected-warning{{TRUE}} + clang_analyzer_eval(a != 0x100); // expected-warning{{comparison of literal 256 with expression of type 'unsigned char' is always true}} expected-warning{{TRUE}} clang_analyzer_eval(a != -1); // expected-warning{{TRUE}} clang_analyzer_eval(a > -1); // expected-warning{{TRUE}} diff --git a/clang/test/Sema/compare.c b/clang/test/Sema/compare.c index 406ade81aa0..e56340ecfeb 100644 --- a/clang/test/Sema/compare.c +++ b/clang/test/Sema/compare.c @@ -93,8 +93,8 @@ int ints(long a, unsigned long b) { // (C,b) (C == (unsigned long) b) + (C == (unsigned int) b) + - (C == (unsigned short) b) + - (C == (unsigned char) b) + + (C == (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}} + (C == (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}} ((long) C == b) + ((int) C == b) + ((short) C == b) + @@ -105,8 +105,8 @@ int ints(long a, unsigned long b) { ((signed char) C == (unsigned char) b) + (C < (unsigned long) b) + (C < (unsigned int) b) + - (C < (unsigned short) b) + - (C < (unsigned char) b) + + (C < (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}} + (C < (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}} ((long) C < b) + ((int) C < b) + ((short) C < b) + @@ -123,8 +123,8 @@ int ints(long a, unsigned long b) { (a == (unsigned char) C) + ((long) a == C) + ((int) a == C) + - ((short) a == C) + - ((signed char) a == C) + + ((short) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always false}} + ((signed char) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always false}} ((long) a == (unsigned long) C) + ((int) a == (unsigned int) C) + ((short) a == (unsigned short) C) + @@ -135,8 +135,8 @@ int ints(long a, unsigned long b) { (a < (unsigned char) C) + ((long) a < C) + ((int) a < C) + - ((short) a < C) + - ((signed char) a < C) + + ((short) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always true}} + ((signed char) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always true}} ((long) a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) C) + // expected-warning {{comparison of integers of different signs}} ((short) a < (unsigned short) C) + @@ -145,8 +145,8 @@ int ints(long a, unsigned long b) { // (0x80000,b) (0x80000 == (unsigned long) b) + (0x80000 == (unsigned int) b) + - (0x80000 == (unsigned short) b) + - (0x80000 == (unsigned char) b) + + (0x80000 == (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}} + (0x80000 == (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}} ((long) 0x80000 == b) + ((int) 0x80000 == b) + ((short) 0x80000 == b) + @@ -157,8 +157,8 @@ int ints(long a, unsigned long b) { ((signed char) 0x80000 == (unsigned char) b) + (0x80000 < (unsigned long) b) + (0x80000 < (unsigned int) b) + - (0x80000 < (unsigned short) b) + - (0x80000 < (unsigned char) b) + + (0x80000 < (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}} + (0x80000 < (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}} ((long) 0x80000 < b) + ((int) 0x80000 < b) + ((short) 0x80000 < b) + @@ -175,8 +175,8 @@ int ints(long a, unsigned long b) { (a == (unsigned char) 0x80000) + ((long) a == 0x80000) + ((int) a == 0x80000) + - ((short) a == 0x80000) + - ((signed char) a == 0x80000) + + ((short) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always false}} + ((signed char) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always false}} ((long) a == (unsigned long) 0x80000) + ((int) a == (unsigned int) 0x80000) + ((short) a == (unsigned short) 0x80000) + @@ -187,8 +187,8 @@ int ints(long a, unsigned long b) { (a < (unsigned char) 0x80000) + ((long) a < 0x80000) + ((int) a < 0x80000) + - ((short) a < 0x80000) + - ((signed char) a < 0x80000) + + ((short) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always true}} + ((signed char) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always true}} ((long) a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) 0x80000) + // expected-warning {{comparison of integers of different signs}} ((short) a < (unsigned short) 0x80000) + diff --git a/clang/test/Sema/outof-range-constant-compare.c b/clang/test/Sema/outof-range-constant-compare.c new file mode 100644 index 00000000000..570971ef8b1 --- /dev/null +++ b/clang/test/Sema/outof-range-constant-compare.c @@ -0,0 +1,149 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare -verify %s +// rdar://12202422 + +int value(void); + +int main() +{ + int a = value(); + if (a == 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a != 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a < 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a <= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a > 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a >= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}} + return 0; + + if (0x1234567812345678L == a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (0x1234567812345678L != a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (0x1234567812345678L < a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (0x1234567812345678L <= a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (0x1234567812345678L > a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (0x1234567812345678L >= a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a == 0x1234567812345678LL) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a == -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a < -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a > -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always true}} + return 0; + if (a <= -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always false}} + return 0; + if (a >= -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always true}} + return 0; + + + if (a == 0x12345678L) // no warning + return 1; + + short s = value(); + if (s == 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (s != 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (s < 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (s <= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (s > 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (s >= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}} + return 0; + + if (0x1234567812345678L == s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (0x1234567812345678L != s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (0x1234567812345678L < s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (0x1234567812345678L <= s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}} + return 0; + if (0x1234567812345678L > s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}} + return 0; + if (0x1234567812345678L >= s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}} + return 0; + long l = value(); + if (l == 0x1234567812345678L) + return 0; + if (l != 0x1234567812345678L) + return 0; + if (l < 0x1234567812345678L) + return 0; + if (l <= 0x1234567812345678L) + return 0; + if (l > 0x1234567812345678L) + return 0; + if (l >= 0x1234567812345678L) + return 0; + + if (0x1234567812345678L == l) + return 0; + if (0x1234567812345678L != l) + return 0; + if (0x1234567812345678L < l) + return 0; + if (0x1234567812345678L <= l) + return 0; + if (0x1234567812345678L > l) + return 0; + if (0x1234567812345678L >= l) + return 0; + + unsigned un = 0; + if (un == 0x0000000000000000L) + return 0; + if (un != 0x0000000000000000L) + return 0; + if (un < 0x0000000000000000L) + return 0; + if (un <= 0x0000000000000000L) + return 0; + if (un > 0x0000000000000000L) + return 0; + if (un >= 0x0000000000000000L) + return 0; + + if (0x0000000000000000L == un) + return 0; + if (0x0000000000000000L != un) + return 0; + if (0x0000000000000000L < un) + return 0; + if (0x0000000000000000L <= un) + return 0; + if (0x0000000000000000L > un) + return 0; + if (0x0000000000000000L >= un) + return 0; + float fl = 0; + if (fl == 0x0000000000000000L) // no warning + return 0; + + float dl = 0; + if (dl == 0x0000000000000000L) // no warning + return 0; + + enum E { + yes, + no, + maybe + }; + enum E e; + + if (e == 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'enum E' is always false}} + return 0; + + return 1; +} diff --git a/clang/test/SemaCXX/compare.cpp b/clang/test/SemaCXX/compare.cpp index 28e2dd0ad51..e6f0575f80b 100644 --- a/clang/test/SemaCXX/compare.cpp +++ b/clang/test/SemaCXX/compare.cpp @@ -89,8 +89,8 @@ int test0(long a, unsigned long b) { // (C,b) (C == (unsigned long) b) + (C == (unsigned int) b) + - (C == (unsigned short) b) + - (C == (unsigned char) b) + + (C == (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}} + (C == (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}} ((long) C == b) + ((int) C == b) + ((short) C == b) + @@ -101,8 +101,8 @@ int test0(long a, unsigned long b) { ((signed char) C == (unsigned char) b) + (C < (unsigned long) b) + (C < (unsigned int) b) + - (C < (unsigned short) b) + - (C < (unsigned char) b) + + (C < (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}} + (C < (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}} ((long) C < b) + ((int) C < b) + ((short) C < b) + @@ -119,8 +119,8 @@ int test0(long a, unsigned long b) { (a == (unsigned char) C) + ((long) a == C) + ((int) a == C) + - ((short) a == C) + - ((signed char) a == C) + + ((short) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always false}} + ((signed char) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always false}} ((long) a == (unsigned long) C) + ((int) a == (unsigned int) C) + ((short) a == (unsigned short) C) + @@ -131,8 +131,8 @@ int test0(long a, unsigned long b) { (a < (unsigned char) C) + ((long) a < C) + ((int) a < C) + - ((short) a < C) + - ((signed char) a < C) + + ((short) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always true}} + ((signed char) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always true}} ((long) a < (unsigned long) C) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) C) + // expected-warning {{comparison of integers of different signs}} ((short) a < (unsigned short) C) + @@ -141,8 +141,8 @@ int test0(long a, unsigned long b) { // (0x80000,b) (0x80000 == (unsigned long) b) + (0x80000 == (unsigned int) b) + - (0x80000 == (unsigned short) b) + - (0x80000 == (unsigned char) b) + + (0x80000 == (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}} + (0x80000 == (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}} ((long) 0x80000 == b) + ((int) 0x80000 == b) + ((short) 0x80000 == b) + @@ -153,8 +153,8 @@ int test0(long a, unsigned long b) { ((signed char) 0x80000 == (unsigned char) b) + (0x80000 < (unsigned long) b) + (0x80000 < (unsigned int) b) + - (0x80000 < (unsigned short) b) + - (0x80000 < (unsigned char) b) + + (0x80000 < (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}} + (0x80000 < (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}} ((long) 0x80000 < b) + ((int) 0x80000 < b) + ((short) 0x80000 < b) + @@ -171,8 +171,8 @@ int test0(long a, unsigned long b) { (a == (unsigned char) 0x80000) + ((long) a == 0x80000) + ((int) a == 0x80000) + - ((short) a == 0x80000) + - ((signed char) a == 0x80000) + + ((short) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always false}} + ((signed char) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always false}} ((long) a == (unsigned long) 0x80000) + ((int) a == (unsigned int) 0x80000) + ((short) a == (unsigned short) 0x80000) + @@ -183,8 +183,8 @@ int test0(long a, unsigned long b) { (a < (unsigned char) 0x80000) + ((long) a < 0x80000) + ((int) a < 0x80000) + - ((short) a < 0x80000) + - ((signed char) a < 0x80000) + + ((short) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always true}} + ((signed char) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always true}} ((long) a < (unsigned long) 0x80000) + // expected-warning {{comparison of integers of different signs}} ((int) a < (unsigned int) 0x80000) + // expected-warning {{comparison of integers of different signs}} ((short) a < (unsigned short) 0x80000) + diff --git a/clang/test/SemaCXX/for-range-examples.cpp b/clang/test/SemaCXX/for-range-examples.cpp index 8bda51062a4..86899bd2ea5 100644 --- a/clang/test/SemaCXX/for-range-examples.cpp +++ b/clang/test/SemaCXX/for-range-examples.cpp @@ -122,12 +122,12 @@ int main() { for (auto n : range(1, 5)) { total += n; } - assert(total == 10); + assert((total == 10)); for (auto n : range(10, 100, 10)) { total += n; } - assert(total == 460); + assert((total == 460)); map_range::vector<char> chars; chars.push_back('a'); @@ -136,7 +136,7 @@ int main() { for (char c : chars) { ++total; } - assert(total == 463); + assert((total == 463)); typedef map_range::tuple<int, double> T; map_range::vector<T> pairs; @@ -146,7 +146,7 @@ int main() { for (auto a : map(map_range::mem_fun(&T::get<int>), pairs)) { total += a; } - assert(total == 500); + assert((total == 500)); } // PR11793 diff --git a/clang/test/SemaCXX/warn-enum-compare.cpp b/clang/test/SemaCXX/warn-enum-compare.cpp index 52639e70a80..68fa2ce3677 100644 --- a/clang/test/SemaCXX/warn-enum-compare.cpp +++ b/clang/test/SemaCXX/warn-enum-compare.cpp @@ -39,8 +39,8 @@ void test () { while (b == c); while (B1 == name1::B2); while (B2 == name2::B1); - while (x == AnonAA); - while (AnonBB == y); + while (x == AnonAA); // expected-warning {{comparison of literal 42 with expression of type 'Foo' is always false}} + while (AnonBB == y); // expected-warning {{comparison of literal 45 with expression of type 'Bar' is always false}} while (AnonAA == AnonAB); while (AnonAB == AnonBA); while (AnonBB == AnonAA); |