diff options
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index caaa08c0bc..e69ebe2250 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -2612,7 +2612,14 @@ void AnalyzeAssignment(Sema &S, BinaryOperator *E) { 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); |