c: warn when an integer value comparison with an
integral expression have the obvious result.
Patch reviewed by John McCall off line.
// rdar://12202422

llvm-svn: 164143
diff --git a/clang/test/SemaCXX/compare.cpp b/clang/test/SemaCXX/compare.cpp
index 28e2dd0..e6f0575 100644
--- a/clang/test/SemaCXX/compare.cpp
+++ b/clang/test/SemaCXX/compare.cpp
@@ -89,8 +89,8 @@
          // (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 @@
          ((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 @@
          (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 @@
          (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 @@
          // (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 @@
          ((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 @@
          (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 @@
          (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 8bda510..86899bd 100644
--- a/clang/test/SemaCXX/for-range-examples.cpp
+++ b/clang/test/SemaCXX/for-range-examples.cpp
@@ -122,12 +122,12 @@
   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 @@
   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 @@
   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 52639e7..68fa2ce 100644
--- a/clang/test/SemaCXX/warn-enum-compare.cpp
+++ b/clang/test/SemaCXX/warn-enum-compare.cpp
@@ -39,8 +39,8 @@
   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);