aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-11-10 00:26:50 +0000
committerJohn McCall <rjmccall@apple.com>2010-11-10 00:26:50 +0000
commit935cd6e8529edbb3b0eba660bd934b508766de37 (patch)
treee0be1c09938fb806774f7ce3ebba0a89ad2969d4 /lib/Sema
parent5dac4c222d9ff25488ac6f0b9642fa0d939ba2f8 (diff)
Tweak to bitfield-overflow warning: don't warn about storing
a positive value into a signed bitfield of the exact width of the value. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118657 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r--lib/Sema/SemaChecking.cpp9
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);