[cfe-commits] r149572 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/constant-conversion.c

Eli Friedman eli.friedman at gmail.com
Wed Feb 1 16:40:21 PST 2012


Author: efriedma
Date: Wed Feb  1 18:40:20 2012
New Revision: 149572

URL: http://llvm.org/viewvc/llvm-project?rev=149572&view=rev
Log:
Change the check for constant-conversion with width-1 bitfields so it doesn't suppress quite as many cases.  Based off a testcase in the gcc testsuite.


Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/constant-conversion.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=149572&r1=149571&r2=149572&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Feb  1 18:40:20 2012
@@ -3758,8 +3758,8 @@
     return false;
 
   // Special-case bitfields of width 1: booleans are naturally 0/1, and
-  // therefore don't strictly fit into a bitfield of width 1.
-  if (FieldWidth == 1 && Value.getBoolValue() == TruncatedValue.getBoolValue())
+  // therefore don't strictly fit into a signed bitfield of width 1.
+  if (FieldWidth == 1 && Value == 1)
     return false;
 
   std::string PrettyValue = Value.toString(10);

Modified: cfe/trunk/test/Sema/constant-conversion.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/constant-conversion.c?rev=149572&r1=149571&r2=149572&view=diff
==============================================================================
--- cfe/trunk/test/Sema/constant-conversion.c (original)
+++ cfe/trunk/test/Sema/constant-conversion.c Wed Feb  1 18:40:20 2012
@@ -74,3 +74,9 @@
 	f.twoBits1 &= ~1; // no-warning
 	f.twoBits2 &= ~2; // no-warning
 }
+
+void test8() {
+  enum E { A, B, C };
+  struct { enum E x : 1; } f;
+  f.x = C; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 2 to 0}}
+}





More information about the cfe-commits mailing list