[cfe-commits] r97430 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/Sema/switch.c
Douglas Gregor
dgregor at apple.com
Sun Feb 28 17:04:55 PST 2010
Author: dgregor
Date: Sun Feb 28 19:04:55 2010
New Revision: 97430
URL: http://llvm.org/viewvc/llvm-project?rev=97430&view=rev
Log:
Don't warn about case-value conversions from a negative value to a
larger unsigned value, since this is implementation-defined
behavior. (We previously suppressed this warning when converting from
a signed value to an unsigned value of the same size).
Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/Sema/switch.c
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=97430&r1=97429&r2=97430&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Feb 28 19:04:55 2010
@@ -314,15 +314,13 @@
// Perform a conversion to the promoted condition type if needed.
if (NewWidth > Val.getBitWidth()) {
// If this is an extension, just do it.
- llvm::APSInt OldVal(Val);
Val.extend(NewWidth);
-
- // If the input was signed and negative and the output is unsigned,
- // warn.
- if (!NewSign && OldVal.isSigned() && OldVal.isNegative())
- Diag(Loc, DiagID) << OldVal.toString(10) << Val.toString(10);
-
Val.setIsSigned(NewSign);
+
+ // If the input was signed and negative and the output is
+ // unsigned, don't bother to warn: this is implementation-defined
+ // behavior.
+ // FIXME: Introduce a second, default-ignored warning for this case?
} else if (NewWidth < Val.getBitWidth()) {
// If this is a truncation, check for overflow.
llvm::APSInt ConvVal(Val);
Modified: cfe/trunk/test/Sema/switch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/switch.c?rev=97430&r1=97429&r2=97430&view=diff
==============================================================================
--- cfe/trunk/test/Sema/switch.c (original)
+++ cfe/trunk/test/Sema/switch.c Sun Feb 28 19:04:55 2010
@@ -254,3 +254,10 @@
}
return 0;
}
+
+void f1(unsigned x) {
+ switch (x) {
+ case -1: break;
+ default: break;
+ }
+}
More information about the cfe-commits
mailing list