]> granicus.if.org Git - clang/commitdiff
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)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168023 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7fd28b61913ee3c87e9253547e8470edd5267962..05fa2a06637745f5bd1984b39d06d4a2a75f8f28 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 155da1b8d10832214dd7504e00a31ed78a5a94a3..05980baf6d673737affeb2e7983e02d1d1406eda 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}}