Tweak to bitfield-overflow warning:  don't warn about storing
a positive value into a signed bitfield of the exact width of
the value.

llvm-svn: 118657
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index caaa08c..e69ebe2 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2612,7 +2612,14 @@
       if (OriginalWidth > FieldWidth) {
         llvm::APSInt TruncatedValue = Value;
         TruncatedValue.trunc(FieldWidth);
-        TruncatedValue.extend(OriginalWidth);
+
+        // It's fairly common to write values into signed bitfields
+        // that, if sign-extended, would end up becoming a different
+        // value.  We don't want to warn about that.
+        if (Value.isSigned() && Value.isNegative())
+          TruncatedValue.sext(OriginalWidth);
+        else
+          TruncatedValue.zext(OriginalWidth);
 
         if (Value != TruncatedValue) {
           std::string PrettyValue = Value.toString(10);