aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-01-10 20:26:42 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-01-10 20:26:42 +0000
commitf6e65cc9a654d54411c43fd014e911a407ad4075 (patch)
tree048f1240d419688a32d43e0082863708518f6b6b
parentd5bfae62aa53290d333211bc5886da786033cfd0 (diff)
Provide a better warning when case value overflows.
// rdar://11577384 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172102 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--lib/Sema/SemaStmt.cpp4
-rw-r--r--test/Sema/switch-1.c4
3 files changed, 7 insertions, 4 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 4563519d57..a67764a573 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5712,6 +5712,9 @@ def warn_bool_switch_condition : Warning<
def warn_case_value_overflow : Warning<
"overflow converting case value to switch condition type (%0 to %1)">,
InGroup<Switch>;
+def warn_case_constant_overflow : Warning<
+ "overflow in case constant expression results in new value (%0)">,
+ InGroup<DiagGroup<"switch">>;
def err_duplicate_case : Error<"duplicate case value '%0'">;
def err_duplicate_case_differing_expr : Error<
"duplicate case value: '%0' and '%1' both equal '%2'">;
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 592c6a6b74..b738793ef9 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -730,8 +730,8 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch,
LoVal = Lo->EvaluateKnownConstInt(Context, &Diags);
if (Diags.size() == 1 &&
Diags[0].second.getDiagID() == diag::note_constexpr_overflow) {
- Diag(Lo->getLocStart(), diag::warn_case_value_overflow) <<
- LoVal.toString(10) << "switch condition value";
+ Diag(Lo->getLocStart(), diag::warn_case_constant_overflow) <<
+ LoVal.toString(10);
Diag(Diags[0].first, Diags[0].second);
}
diff --git a/test/Sema/switch-1.c b/test/Sema/switch-1.c
index b45cbdbf2f..2b729ac0ad 100644
--- a/test/Sema/switch-1.c
+++ b/test/Sema/switch-1.c
@@ -5,10 +5,10 @@
int f(int i) {
switch (i) {
case 2147483647 + 2: // expected-note {{value 2147483649 is outside the range of representable values of type 'int'}} \
- // expected-warning {{overflow converting case value to switch condition type}}
+ // expected-warning {{overflow in case constant expression results in new value (-2147483647)}}
return 1;
case 9223372036854775807L * 4 : // expected-note {{value 36893488147419103228 is outside the range of representable values of type 'long'}} \
- // expected-warning {{overflow converting case value to switch condition type}}
+ // expected-warning {{overflow in case constant expression results in new value (-4)}}
return 2;
case 2147483647:
return 0;