Fix an off-by-one error by switching < to <= in -Wtautological-constant-out-of-range...
authorRichard Trieu <rtrieu@google.com>
Thu, 15 Nov 2012 03:43:50 +0000 (03:43 +0000)
committerRichard Trieu <rtrieu@google.com>
Thu, 15 Nov 2012 03:43:50 +0000 (03:43 +0000)
llvm-svn: 168023

clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/compare.cpp

index 7fd28b6..05fa2a0 100644 (file)
@@ -4385,7 +4385,7 @@ static void DiagnoseOutOfRangeComparison(Sema &S, BinaryOperator *E,
       // Check to see if the constant is equivalent to a negative value
       // cast to CommonT.
       if (S.Context.getIntWidth(ConstantT) == S.Context.getIntWidth(CommonT) &&
-          Value.isNegative() && Value.getMinSignedBits() < OtherWidth)
+          Value.isNegative() && Value.getMinSignedBits() <= OtherWidth)
         return;
       // The constant value rests between values that OtherT can represent after
       // conversion.  Relational comparison still works, but equality
index 155da1b..05980ba 100644 (file)
@@ -311,6 +311,7 @@ void test7(unsigned long other) {
   (void)((int)other != (unsigned long)(0x00000000ffffffff)); // expected-warning{{true}}
   (void)((int)other != (unsigned long)(0x000000000fffffff));
   (void)((int)other < (unsigned long)(0x00000000ffffffff));  // expected-warning{{different signs}}
+  (void)((int)other == (unsigned)(0x800000000));
 
   // Common unsigned, other unsigned, constant signed
   (void)((unsigned long)other != (int)(0xffffffff));  // expected-warning{{different signs}}