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.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149572 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index ee04463..9dbee1b 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -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);
diff --git a/test/Sema/constant-conversion.c b/test/Sema/constant-conversion.c
index e3097f8..1376333 100644
--- a/test/Sema/constant-conversion.c
+++ b/test/Sema/constant-conversion.c
@@ -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}}
+}