On Tue, Sep 18, 2012 at 10:37 AM, Fariborz Jahanian <span dir="ltr"><<a href="mailto:fjahanian@apple.com" target="_blank">fjahanian@apple.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: fjahanian<br>
Date: Tue Sep 18 12:37:21 2012<br>
New Revision: 164143<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=164143&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=164143&view=rev</a><br>
Log:<br>
c: warn when an integer value comparison with an<br>
integral expression have the obvious result.<br>
Patch reviewed by John McCall off line.<br>
// rdar://12202422<br>
<br>
Added:<br>
    cfe/trunk/test/Sema/outof-range-constant-compare.c<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
    cfe/trunk/lib/Sema/SemaChecking.cpp<br>
    cfe/trunk/test/Analysis/additive-folding.cpp<br>
    cfe/trunk/test/Sema/compare.c<br>
    cfe/trunk/test/SemaCXX/compare.cpp<br>
    cfe/trunk/test/SemaCXX/for-range-examples.cpp<br>
    cfe/trunk/test/SemaCXX/warn-enum-compare.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=164143&r1=164142&r2=164143&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=164143&r1=164142&r2=164143&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Sep 18 12:37:21 2012<br>
@@ -196,6 +196,7 @@<br>
 def StringPlusInt : DiagGroup<"string-plus-int">;<br>
 def StrncatSize : DiagGroup<"strncat-size">;<br>
 def TautologicalCompare : DiagGroup<"tautological-compare">;<br>
+def TautologicalOutofRangeCompare : DiagGroup<"tautological-constant-out-of-range-compare">;<br></blockquote><div><br></div><div>Have you considered making this be a subgroup of -Wtautological-compare?</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 def HeaderHygiene : DiagGroup<"header-hygiene">;<br>
 def DuplicateDeclSpecifier : DiagGroup<"duplicate-decl-specifier">;<br>
<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=164143&r1=164142&r2=164143&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=164143&r1=164142&r2=164143&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Sep 18 12:37:21 2012<br>
@@ -4068,6 +4068,9 @@<br>
 def warn_lunsigned_always_true_comparison : Warning<<br>
   "comparison of unsigned%select{| enum}2 expression %0 is always %1">,<br>
   InGroup<TautologicalCompare>;<br>
+def warn_outof_range_compare : Warning<<br>
+  "comparison of literal %0 with expression of type %1 is always "<br>
+  "%select{false|true}2">, InGroup<TautologicalOutofRangeCompare>;<br></blockquote><div><br></div><div>Should this be warn_out_of_range_compare, and TautologicalOutOfRangeCompare?</div><div><br></div>
<div>Also, the constant operand isn't always a literal:</div><div><br></div><div><div><stdin>:1:50: warning: comparison of literal 10000 with expression of type 'unsigned char' is always false [-Wtautological-constant-out-of-range-compare]</div>
<div>const int n = 10000; unsigned char c; bool b = n == c;</div><div>                                               ~ ^  ~</div></div><div><br></div><div>Perhaps 'comparison of constant 10000 with expression of type ...'.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 def warn_runsigned_always_true_comparison : Warning<<br>
   "comparison of %0 unsigned%select{| enum}2 expression is always %1">,<br>
   InGroup<TautologicalCompare>;<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=164143&r1=164142&r2=164143&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=164143&r1=164142&r2=164143&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Sep 18 12:37:21 2012<br>
@@ -4301,6 +4301,45 @@<br>
   }<br>
 }<br>
<br>
+static void DiagnoseOutOfRangeComparison(Sema &S, BinaryOperator *E,<br>
+                                         Expr *lit, Expr *other,<br>
+                                         llvm::APSInt Value,<br>
+                                         bool rhsLiteral) {<br></blockquote><div><br></div><div>Please capitalize all of these.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+  BinaryOperatorKind op = E->getOpcode();<br>
+  QualType OtherT = other->getType();<br>
+  const Type *OtherPtrT = S.Context.getCanonicalType(OtherT).getTypePtr();<br>
+  const Type *LitPtrT = S.Context.getCanonicalType(lit->getType()).getTypePtr();<br>
+  if (OtherPtrT == LitPtrT)<br>
+    return;<br></blockquote><div><br></div><div>This is S.getContext().hasSameUnqualifiedType(OtherT, Lit->getType()).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+  assert((OtherT->isIntegerType() && LitPtrT->isIntegerType())<br>
+         && "comparison with non-integer type");<br>
+  IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);<br></blockquote><div><br></div><div><div>Have you considered using GetExprRange on the non-constant expression, in order to catch more cases of tautological comparisons (bitwise operations on one of the operands, and the like).</div>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+  IntRange LitRange = GetExprRange(S.Context, lit);<br></blockquote><div><br></div><div>This is recomputing the constant Value that the caller just passed in.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+  if (OtherRange.Width >= LitRange.Width)<br>
+    return;<br></blockquote><div><br></div><div>Do you not need to check signedness here? (signed char)N == 200 isn't caught by this check.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+  std::string PrettySourceValue = Value.toString(10);<br></blockquote><div><br></div><div>Rather than going to the heap, how about an llvm::SmallString here?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+  bool IsTrue = true;<br>
+  if (op == BO_EQ)<br>
+    IsTrue = false;<br>
+  else if (op == BO_NE)<br>
+    IsTrue = true;<br>
+  else if (rhsLiteral) {<br>
+    if (op == BO_GT || op == BO_GE)<br>
+      IsTrue = !LitRange.NonNegative;<br>
+    else // op == BO_LT || op == BO_LE<br>
+      IsTrue = LitRange.NonNegative;<br>
+  }<br>
+  else {<br></blockquote><div><br></div><div>No linebreak here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    if (op == BO_LT || op == BO_LE)<br>
+      IsTrue = !LitRange.NonNegative;<br>
+    else // op == BO_GT || op == BO_GE<br>
+      IsTrue = LitRange.NonNegative;<br>
+  }<br>
+  S.Diag(E->getOperatorLoc(), diag::warn_outof_range_compare)<br>
+  << PrettySourceValue << other->getType() << IsTrue<br>
+  << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();<br>
+}<br>
+<br>
 /// Analyze the operands of the given comparison.  Implements the<br>
 /// fallback case from AnalyzeComparison.<br>
 static void AnalyzeImpConvsInComparison(Sema &S, BinaryOperator *E) {<br>
@@ -4317,19 +4356,42 @@<br>
   assert(S.Context.hasSameUnqualifiedType(T, E->getRHS()->getType())<br>
          && "comparison with mismatched types");<br>
<br>
+  Expr *LHS = E->getLHS()->IgnoreParenImpCasts();<br>
+  Expr *RHS = E->getRHS()->IgnoreParenImpCasts();<br>
+  if (E->isValueDependent())<br>
+    return AnalyzeImpConvsInComparison(S, E);<br>
+<br>
+  bool IsComparisonConstant = false;<br>
+<br>
+  // Check that an integer constant comparison results in a value<br>
+  // of 'true' or 'false'.<br></blockquote><div><br></div><div>"// Check whether an [...]" ?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+  if (T->isIntegralType(S.Context)) {<br>
+    llvm::APSInt RHSValue;<br>
+    bool IsRHSIntegralLiteral =<br>
+      RHS->isIntegerConstantExpr(RHSValue, S.Context);<br>
+    llvm::APSInt LHSValue;<br>
+    bool IsLHSIntegralLiteral =<br>
+      LHS->isIntegerConstantExpr(LHSValue, S.Context);<br>
+    if (IsRHSIntegralLiteral && !IsLHSIntegralLiteral)<br>
+        DiagnoseOutOfRangeComparison(S, E, RHS, LHS, RHSValue, true);<br>
+    else if (!IsRHSIntegralLiteral && IsLHSIntegralLiteral)<br>
+      DiagnoseOutOfRangeComparison(S, E, LHS, RHS, LHSValue, false);<br>
+    else<br>
+      IsComparisonConstant =<br>
+        (IsRHSIntegralLiteral && IsLHSIntegralLiteral);<br>
+  }<br>
+  else if (!T->hasUnsignedIntegerRepresentation())<br></blockquote><div><br></div><div>No linebreak here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

+    IsComparisonConstant = E->isIntegerConstantExpr(S.Context);<br>
+<br>
   // We don't do anything special if this isn't an unsigned integral<br>
   // comparison:  we're only interested in integral comparisons, and<br>
   // signed comparisons only happen in cases we don't care to warn about.<br>
   //<br>
   // We also don't care about value-dependent expressions or expressions<br>
   // whose result is a constant.<br>
-  if (!T->hasUnsignedIntegerRepresentation()<br>
-      || E->isValueDependent() || E->isIntegerConstantExpr(S.Context))<br>
+  if (!T->hasUnsignedIntegerRepresentation() || IsComparisonConstant)<br>
     return AnalyzeImpConvsInComparison(S, E);<br>
-<br>
-  Expr *LHS = E->getLHS()->IgnoreParenImpCasts();<br>
-  Expr *RHS = E->getRHS()->IgnoreParenImpCasts();<br>
-<br>
+<br>
   // Check to see if one of the (unmodified) operands is of different<br>
   // signedness.<br>
   Expr *signedOperand, *unsignedOperand;<br>
<br>
Modified: cfe/trunk/test/Analysis/additive-folding.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/additive-folding.cpp?rev=164143&r1=164142&r2=164143&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/additive-folding.cpp?rev=164143&r1=164142&r2=164143&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/Analysis/additive-folding.cpp (original)<br>
+++ cfe/trunk/test/Analysis/additive-folding.cpp Tue Sep 18 12:37:21 2012<br>
@@ -128,10 +128,10 @@<br>
<br>
 // Tautologies from outside the range of the symbol<br>
 void tautologiesOutside(unsigned char a) {<br>
-  clang_analyzer_eval(a <= 0x100); // expected-warning{{TRUE}}<br>
-  clang_analyzer_eval(a < 0x100); // expected-warning{{TRUE}}<br>
+  clang_analyzer_eval(a <= 0x100); // expected-warning{{comparison of literal 256 with expression of type 'unsigned char' is always true}} expected-warning{{TRUE}}<br>
+  clang_analyzer_eval(a < 0x100); // expected-warning{{comparison of literal 256 with expression of type 'unsigned char' is always true}} expected-warning{{TRUE}}<br>
<br>
-  clang_analyzer_eval(a != 0x100); // expected-warning{{TRUE}}<br>
+  clang_analyzer_eval(a != 0x100); // expected-warning{{comparison of literal 256 with expression of type 'unsigned char' is always true}} expected-warning{{TRUE}}<br>
   clang_analyzer_eval(a != -1); // expected-warning{{TRUE}}<br>
<br>
   clang_analyzer_eval(a > -1); // expected-warning{{TRUE}}<br>
<br>
Modified: cfe/trunk/test/Sema/compare.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=164143&r1=164142&r2=164143&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=164143&r1=164142&r2=164143&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/Sema/compare.c (original)<br>
+++ cfe/trunk/test/Sema/compare.c Tue Sep 18 12:37:21 2012<br>
@@ -93,8 +93,8 @@<br>
          // (C,b)<br>
          (C == (unsigned long) b) +<br>
          (C == (unsigned int) b) +<br>
-         (C == (unsigned short) b) +<br>
-         (C == (unsigned char) b) +<br>
+         (C == (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}}<br>
+         (C == (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}}<br>
          ((long) C == b) +<br>
          ((int) C == b) +<br>
          ((short) C == b) +<br>
@@ -105,8 +105,8 @@<br>
          ((signed char) C == (unsigned char) b) +<br>
          (C < (unsigned long) b) +<br>
          (C < (unsigned int) b) +<br>
-         (C < (unsigned short) b) +<br>
-         (C < (unsigned char) b) +<br>
+         (C < (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}}<br>
+         (C < (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}}<br>
          ((long) C < b) +<br>
          ((int) C < b) +<br>
          ((short) C < b) +<br>
@@ -123,8 +123,8 @@<br>
          (a == (unsigned char) C) +<br>
          ((long) a == C) +<br>
          ((int) a == C) +<br>
-         ((short) a == C) +<br>
-         ((signed char) a == C) +<br>
+         ((short) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always false}}<br>
+         ((signed char) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always false}}<br>
          ((long) a == (unsigned long) C) +<br>
          ((int) a == (unsigned int) C) +<br>
          ((short) a == (unsigned short) C) +<br>
@@ -135,8 +135,8 @@<br>
          (a < (unsigned char) C) +<br>
          ((long) a < C) +<br>
          ((int) a < C) +<br>
-         ((short) a < C) +<br>
-         ((signed char) a < C) +<br>
+         ((short) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always true}}<br>
+         ((signed char) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always true}}<br>
          ((long) a < (unsigned long) C) +  // expected-warning {{comparison of integers of different signs}}<br>
          ((int) a < (unsigned int) C) +  // expected-warning {{comparison of integers of different signs}}<br>
          ((short) a < (unsigned short) C) +<br>
@@ -145,8 +145,8 @@<br>
          // (0x80000,b)<br>
          (0x80000 == (unsigned long) b) +<br>
          (0x80000 == (unsigned int) b) +<br>
-         (0x80000 == (unsigned short) b) +<br>
-         (0x80000 == (unsigned char) b) +<br>
+         (0x80000 == (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}}<br>
+         (0x80000 == (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}}<br>
          ((long) 0x80000 == b) +<br>
          ((int) 0x80000 == b) +<br>
          ((short) 0x80000 == b) +<br>
@@ -157,8 +157,8 @@<br>
          ((signed char) 0x80000 == (unsigned char) b) +<br>
          (0x80000 < (unsigned long) b) +<br>
          (0x80000 < (unsigned int) b) +<br>
-         (0x80000 < (unsigned short) b) +<br>
-         (0x80000 < (unsigned char) b) +<br>
+         (0x80000 < (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}}<br>
+         (0x80000 < (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}}<br>
          ((long) 0x80000 < b) +<br>
          ((int) 0x80000 < b) +<br>
          ((short) 0x80000 < b) +<br>
@@ -175,8 +175,8 @@<br>
          (a == (unsigned char) 0x80000) +<br>
          ((long) a == 0x80000) +<br>
          ((int) a == 0x80000) +<br>
-         ((short) a == 0x80000) +<br>
-         ((signed char) a == 0x80000) +<br>
+         ((short) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always false}}<br>
+         ((signed char) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always false}}<br>
          ((long) a == (unsigned long) 0x80000) +<br>
          ((int) a == (unsigned int) 0x80000) +<br>
          ((short) a == (unsigned short) 0x80000) +<br>
@@ -187,8 +187,8 @@<br>
          (a < (unsigned char) 0x80000) +<br>
          ((long) a < 0x80000) +<br>
          ((int) a < 0x80000) +<br>
-         ((short) a < 0x80000) +<br>
-         ((signed char) a < 0x80000) +<br>
+         ((short) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always true}}<br>
+         ((signed char) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always true}}<br>
          ((long) a < (unsigned long) 0x80000) +  // expected-warning {{comparison of integers of different signs}}<br>
          ((int) a < (unsigned int) 0x80000) +  // expected-warning {{comparison of integers of different signs}}<br>
          ((short) a < (unsigned short) 0x80000) +<br>
<br>
Added: cfe/trunk/test/Sema/outof-range-constant-compare.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/outof-range-constant-compare.c?rev=164143&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/outof-range-constant-compare.c?rev=164143&view=auto</a><br>

==============================================================================<br>
--- cfe/trunk/test/Sema/outof-range-constant-compare.c (added)<br>
+++ cfe/trunk/test/Sema/outof-range-constant-compare.c Tue Sep 18 12:37:21 2012<br>
@@ -0,0 +1,149 @@<br>
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -Wtautological-constant-out-of-range-compare -verify %s<br>
+// rdar://12202422<br>
+<br>
+int value(void);<br>
+<br>
+int main()<br>
+{<br>
+    int a = value();<br>
+    if (a == 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}<br>
+        return 0;<br>
+    if (a != 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}<br>
+        return 0;<br>
+    if (a < 0x1234567812345678L)  // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}<br>
+        return 0;<br>
+    if (a <= 0x1234567812345678L)  // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}<br>
+        return 0;<br>
+    if (a > 0x1234567812345678L)  // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}<br>
+        return 0;<br>
+    if (a >= 0x1234567812345678L)  // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}<br>
+        return 0;<br>
+<br>
+    if (0x1234567812345678L == a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}<br>
+        return 0;<br>
+    if (0x1234567812345678L != a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}<br>
+        return 0;<br>
+    if (0x1234567812345678L < a)  // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}<br>
+        return 0;<br>
+    if (0x1234567812345678L <= a)  // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}<br>
+        return 0;<br>
+    if (0x1234567812345678L > a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}<br>
+        return 0;<br>
+    if (0x1234567812345678L >= a) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always true}}<br>
+        return 0;<br>
+    if (a == 0x1234567812345678LL) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'int' is always false}}<br>
+      return 0;<br>
+    if (a == -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always false}}<br>
+      return 0;<br>
+    if (a < -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always false}}<br>
+      return 0;<br>
+    if (a > -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always true}}<br>
+      return 0;<br>
+    if (a <= -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always false}}<br>
+      return 0;<br>
+    if (a >= -0x1234567812345678L) // expected-warning {{comparison of literal -1311768465173141112 with expression of type 'int' is always true}}<br>
+      return 0;<br>
+<br>
+<br>
+    if (a == 0x12345678L) // no warning<br>
+      return 1;<br>
+<br>
+    short s = value();<br>
+    if (s == 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}<br>
+        return 0;<br>
+    if (s != 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}<br>
+        return 0;<br>
+    if (s < 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}<br>
+        return 0;<br>
+    if (s <= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}<br>
+        return 0;<br>
+    if (s > 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}<br>
+        return 0;<br>
+    if (s >= 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}<br>
+        return 0;<br>
+<br>
+    if (0x1234567812345678L == s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}<br>
+        return 0;<br>
+    if (0x1234567812345678L != s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}<br>
+        return 0;<br>
+    if (0x1234567812345678L < s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}<br>
+        return 0;<br>
+    if (0x1234567812345678L <= s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always false}}<br>
+        return 0;<br>
+    if (0x1234567812345678L > s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}<br>
+        return 0;<br>
+    if (0x1234567812345678L >= s) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'short' is always true}}<br>
+        return 0;<br>
+    long l = value();<br>
+    if (l == 0x1234567812345678L)<br>
+        return 0;<br>
+    if (l != 0x1234567812345678L)<br>
+        return 0;<br>
+    if (l < 0x1234567812345678L)<br>
+        return 0;<br>
+    if (l <= 0x1234567812345678L)<br>
+        return 0;<br>
+    if (l > 0x1234567812345678L)<br>
+        return 0;<br>
+    if (l >= 0x1234567812345678L)<br>
+        return 0;<br>
+<br>
+    if (0x1234567812345678L == l)<br>
+        return 0;<br>
+    if (0x1234567812345678L != l)<br>
+        return 0;<br>
+    if (0x1234567812345678L < l)<br>
+        return 0;<br>
+    if (0x1234567812345678L <= l)<br>
+        return 0;<br>
+    if (0x1234567812345678L > l)<br>
+        return 0;<br>
+    if (0x1234567812345678L >= l)<br>
+        return 0;<br>
+<br>
+    unsigned un = 0;<br>
+    if (un == 0x0000000000000000L)<br>
+        return 0;<br>
+    if (un != 0x0000000000000000L)<br>
+        return 0;<br>
+    if (un < 0x0000000000000000L)<br>
+        return 0;<br>
+    if (un <= 0x0000000000000000L)<br>
+        return 0;<br>
+    if (un > 0x0000000000000000L)<br>
+        return 0;<br>
+    if (un >= 0x0000000000000000L)<br>
+        return 0;<br>
+<br>
+    if (0x0000000000000000L == un)<br>
+        return 0;<br>
+    if (0x0000000000000000L != un)<br>
+        return 0;<br>
+    if (0x0000000000000000L < un)<br>
+        return 0;<br>
+    if (0x0000000000000000L <= un)<br>
+        return 0;<br>
+    if (0x0000000000000000L > un)<br>
+        return 0;<br>
+    if (0x0000000000000000L >= un)<br>
+        return 0;<br>
+    float fl = 0;<br>
+    if (fl == 0x0000000000000000L) // no warning<br>
+      return 0;<br>
+<br>
+    float dl = 0;<br>
+    if (dl == 0x0000000000000000L) // no warning<br>
+      return 0;<br>
+<br>
+    enum E {<br>
+    yes,<br>
+    no,<br>
+    maybe<br>
+    };<br>
+    enum E e;<br>
+<br>
+    if (e == 0x1234567812345678L) // expected-warning {{comparison of literal 1311768465173141112 with expression of type 'enum E' is always false}}<br>
+      return 0;<br>
+<br>
+    return 1;<br>
+}<br>
<br>
Modified: cfe/trunk/test/SemaCXX/compare.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=164143&r1=164142&r2=164143&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=164143&r1=164142&r2=164143&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaCXX/compare.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/compare.cpp Tue Sep 18 12:37:21 2012<br>
@@ -89,8 +89,8 @@<br>
          // (C,b)<br>
          (C == (unsigned long) b) +<br>
          (C == (unsigned int) b) +<br>
-         (C == (unsigned short) b) +<br>
-         (C == (unsigned char) b) +<br>
+         (C == (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}}<br>
+         (C == (unsigned char) b) +  // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}}<br>
          ((long) C == b) +<br>
          ((int) C == b) +<br>
          ((short) C == b) +<br>
@@ -101,8 +101,8 @@<br>
          ((signed char) C == (unsigned char) b) +<br>
          (C < (unsigned long) b) +<br>
          (C < (unsigned int) b) +<br>
-         (C < (unsigned short) b) +<br>
-         (C < (unsigned char) b) +<br>
+         (C < (unsigned short) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned short' is always false}}<br>
+         (C < (unsigned char) b) + // expected-warning {{comparison of literal 65536 with expression of type 'unsigned char' is always false}}<br>
          ((long) C < b) +<br>
          ((int) C < b) +<br>
          ((short) C < b) +<br>
@@ -119,8 +119,8 @@<br>
          (a == (unsigned char) C) +<br>
          ((long) a == C) +<br>
          ((int) a == C) +<br>
-         ((short) a == C) +<br>
-         ((signed char) a == C) +<br>
+         ((short) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always false}}<br>
+         ((signed char) a == C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always false}}<br>
          ((long) a == (unsigned long) C) +<br>
          ((int) a == (unsigned int) C) +<br>
          ((short) a == (unsigned short) C) +<br>
@@ -131,8 +131,8 @@<br>
          (a < (unsigned char) C) +<br>
          ((long) a < C) +<br>
          ((int) a < C) +<br>
-         ((short) a < C) +<br>
-         ((signed char) a < C) +<br>
+         ((short) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'short' is always true}}<br>
+         ((signed char) a < C) + // expected-warning {{comparison of literal 65536 with expression of type 'signed char' is always true}}<br>
          ((long) a < (unsigned long) C) +  // expected-warning {{comparison of integers of different signs}}<br>
          ((int) a < (unsigned int) C) +  // expected-warning {{comparison of integers of different signs}}<br>
          ((short) a < (unsigned short) C) +<br>
@@ -141,8 +141,8 @@<br>
          // (0x80000,b)<br>
          (0x80000 == (unsigned long) b) +<br>
          (0x80000 == (unsigned int) b) +<br>
-         (0x80000 == (unsigned short) b) +<br>
-         (0x80000 == (unsigned char) b) +<br>
+         (0x80000 == (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}}<br>
+         (0x80000 == (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}}<br>
          ((long) 0x80000 == b) +<br>
          ((int) 0x80000 == b) +<br>
          ((short) 0x80000 == b) +<br>
@@ -153,8 +153,8 @@<br>
          ((signed char) 0x80000 == (unsigned char) b) +<br>
          (0x80000 < (unsigned long) b) +<br>
          (0x80000 < (unsigned int) b) +<br>
-         (0x80000 < (unsigned short) b) +<br>
-         (0x80000 < (unsigned char) b) +<br>
+         (0x80000 < (unsigned short) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned short' is always false}}<br>
+         (0x80000 < (unsigned char) b) + // expected-warning {{comparison of literal 524288 with expression of type 'unsigned char' is always false}}<br>
          ((long) 0x80000 < b) +<br>
          ((int) 0x80000 < b) +<br>
          ((short) 0x80000 < b) +<br>
@@ -171,8 +171,8 @@<br>
          (a == (unsigned char) 0x80000) +<br>
          ((long) a == 0x80000) +<br>
          ((int) a == 0x80000) +<br>
-         ((short) a == 0x80000) +<br>
-         ((signed char) a == 0x80000) +<br>
+         ((short) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always false}}<br>
+         ((signed char) a == 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always false}}<br>
          ((long) a == (unsigned long) 0x80000) +<br>
          ((int) a == (unsigned int) 0x80000) +<br>
          ((short) a == (unsigned short) 0x80000) +<br>
@@ -183,8 +183,8 @@<br>
          (a < (unsigned char) 0x80000) +<br>
          ((long) a < 0x80000) +<br>
          ((int) a < 0x80000) +<br>
-         ((short) a < 0x80000) +<br>
-         ((signed char) a < 0x80000) +<br>
+         ((short) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'short' is always true}}<br>
+         ((signed char) a < 0x80000) + // expected-warning {{comparison of literal 524288 with expression of type 'signed char' is always true}}<br>
          ((long) a < (unsigned long) 0x80000) +  // expected-warning {{comparison of integers of different signs}}<br>
          ((int) a < (unsigned int) 0x80000) +  // expected-warning {{comparison of integers of different signs}}<br>
          ((short) a < (unsigned short) 0x80000) +<br>
<br>
Modified: cfe/trunk/test/SemaCXX/for-range-examples.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/for-range-examples.cpp?rev=164143&r1=164142&r2=164143&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/for-range-examples.cpp?rev=164143&r1=164142&r2=164143&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaCXX/for-range-examples.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/for-range-examples.cpp Tue Sep 18 12:37:21 2012<br>
@@ -122,12 +122,12 @@<br>
   for (auto n : range(1, 5)) {<br>
     total += n;<br>
   }<br>
-  assert(total == 10);<br>
+  assert((total == 10));<br></blockquote><div><br></div><div>Please fix the definition of assert, not its uses.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
   for (auto n : range(10, 100, 10)) {<br>
     total += n;<br>
   }<br>
-  assert(total == 460);<br>
+  assert((total == 460));<br>
<br>
   map_range::vector<char> chars;<br>
   chars.push_back('a');<br>
@@ -136,7 +136,7 @@<br>
   for (char c : chars) {<br>
     ++total;<br>
   }<br>
-  assert(total == 463);<br>
+  assert((total == 463));<br>
<br>
   typedef map_range::tuple<int, double> T;<br>
   map_range::vector<T> pairs;<br>
@@ -146,7 +146,7 @@<br>
   for (auto a : map(map_range::mem_fun(&T::get<int>), pairs)) {<br>
     total += a;<br>
   }<br>
-  assert(total == 500);<br>
+  assert((total == 500));<br>
 }<br>
<br>
 // PR11793<br>
<br>
Modified: cfe/trunk/test/SemaCXX/warn-enum-compare.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-enum-compare.cpp?rev=164143&r1=164142&r2=164143&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-enum-compare.cpp?rev=164143&r1=164142&r2=164143&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaCXX/warn-enum-compare.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/warn-enum-compare.cpp Tue Sep 18 12:37:21 2012<br>
@@ -39,8 +39,8 @@<br>
   while (b == c);<br>
   while (B1 == name1::B2);<br>
   while (B2 == name2::B1);<br>
-  while (x == AnonAA);<br>
-  while (AnonBB == y);<br>
+  while (x == AnonAA); // expected-warning {{comparison of literal 42 with expression of type 'Foo' is always false}}<br>
+  while (AnonBB == y); // expected-warning {{comparison of literal 45 with expression of type 'Bar' is always false}}<br>
   while (AnonAA == AnonAB);<br>
   while (AnonAB == AnonBA);<br>
   while (AnonBB == AnonAA);</blockquote></div>