[cfe-commits] r169051 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/compare.cpp

Eli Friedman eli.friedman at gmail.com
Fri Nov 30 15:09:30 PST 2012


Author: efriedma
Date: Fri Nov 30 17:09:29 2012
New Revision: 169051

URL: http://llvm.org/viewvc/llvm-project?rev=169051&view=rev
Log:
Make -Wtautological-constant-out-of-range-compare behave sanely for enums with a signed fixed type.
<rdar://problem/12780159>.


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=169051&r1=169050&r2=169051&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Nov 30 17:09:29 2012
@@ -4346,7 +4346,6 @@
          && "comparison with non-integer type");
 
   bool ConstantSigned = ConstantT->isSignedIntegerType();
-  bool OtherSigned = OtherT->isSignedIntegerType();
   bool CommonSigned = CommonT->isSignedIntegerType();
 
   bool EqualityOnly = false;
@@ -4358,7 +4357,7 @@
   
   if (CommonSigned) {
     // The common type is signed, therefore no signed to unsigned conversion.
-    if (OtherSigned) {
+    if (!OtherRange.NonNegative) {
       // Check that the constant is representable in type OtherT.
       if (ConstantSigned) {
         if (OtherWidth >= Value.getMinSignedBits())
@@ -4379,10 +4378,10 @@
       }
     }
   } else {  // !CommonSigned
-    if (!OtherSigned) {
+    if (OtherRange.NonNegative) {
       if (OtherWidth >= Value.getActiveBits())
         return;
-    } else if (OtherSigned && !ConstantSigned) {
+    } else if (!OtherRange.NonNegative && !ConstantSigned) {
       // Check to see if the constant is representable in OtherT.
       if (OtherWidth > Value.getActiveBits())
         return;

Modified: cfe/trunk/test/SemaCXX/compare.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare.cpp?rev=169051&r1=169050&r2=169051&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/compare.cpp (original)
+++ cfe/trunk/test/SemaCXX/compare.cpp Fri Nov 30 17:09:29 2012
@@ -1,7 +1,7 @@
 // Force x86-64 because some of our heuristics are actually based
 // on integer sizes.
 
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify -Wsign-compare -std=c++11 %s
 
 int test0(long a, unsigned long b) {
   enum EnumA {A};
@@ -348,3 +348,10 @@
   (void)((E)x == 1);
   (void)((E)x == -1);
 }
+
+void test9(int x) {
+  enum E : int {
+    Positive = 1
+  };
+  (void)((E)x == 1);
+}





More information about the cfe-commits mailing list