aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaStmt.cpp12
-rw-r--r--test/Sema/switch.c7
2 files changed, 12 insertions, 7 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index bdd0962a11..540189cd83 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -314,15 +314,13 @@ void Sema::ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &Val,
// 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);
diff --git a/test/Sema/switch.c b/test/Sema/switch.c
index 213cd0a75b..e63a1942bb 100644
--- a/test/Sema/switch.c
+++ b/test/Sema/switch.c
@@ -254,3 +254,10 @@ int test14(int a) {
}
return 0;
}
+
+void f1(unsigned x) {
+ switch (x) {
+ case -1: break;
+ default: break;
+ }
+}