From: Richard Trieu Date: Thu, 15 Nov 2012 03:43:50 +0000 (+0000) Subject: Fix an off-by-one error by switching < to <= in -Wtautological-constant-out-of-range... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5d1cf4f292cb060b1973eb197607fc6d5716bd12;p=clang Fix an off-by-one error by switching < to <= in -Wtautological-constant-out-of-range-compare and added test case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168023 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 7fd28b6191..05fa2a0663 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -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 diff --git a/test/SemaCXX/compare.cpp b/test/SemaCXX/compare.cpp index 155da1b8d1..05980baf6d 100644 --- a/test/SemaCXX/compare.cpp +++ b/test/SemaCXX/compare.cpp @@ -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}}