[cfe-commits] r168126 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/compare.cpp
Richard Trieu
rtrieu at google.com
Thu Nov 15 17:32:41 PST 2012
Author: rtrieu
Date: Thu Nov 15 19:32:40 2012
New Revision: 168126
URL: http://llvm.org/viewvc/llvm-project?rev=168126&view=rev
Log:
Take into account the zero sign bit for positive numbers when computing the bit
width of an enum with negative values in IntRange. Include a test for
-Wtautological-constant-out-of-range-compare where this had manifested.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/compare.cpp
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=168126&r1=168125&r2=168126&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Nov 15 19:32:40 2012
@@ -3922,7 +3922,11 @@
unsigned NumPositive = Enum->getNumPositiveBits();
unsigned NumNegative = Enum->getNumNegativeBits();
- return IntRange(std::max(NumPositive, NumNegative), NumNegative == 0);
+ if (NumNegative == 0)
+ return IntRange(NumPositive, true/*NonNegative*/);
+ else
+ return IntRange(std::max(NumPositive + 1, NumNegative),
+ false/*NonNegative*/);
}
const BuiltinType *BT = cast<BuiltinType>(T);
Modified: cfe/trunk/test/SemaCXX/compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=168126&r1=168125&r2=168126&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/compare.cpp Thu Nov 15 19:32:40 2012
@@ -338,3 +338,13 @@
(void)((unsigned char)other != (unsigned short)(0x100)); // expected-warning{{true}}
(void)((unsigned short)other != (unsigned char)(0xff));
}
+
+void test8(int x) {
+ enum E {
+ Negative = -1,
+ Positive = 1
+ };
+
+ (void)((E)x == 1);
+ (void)((E)x == -1);
+}
More information about the cfe-commits
mailing list