aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2008-12-01 02:13:02 +0000
committerAnders Carlsson <andersca@mac.com>2008-12-01 02:13:02 +0000
commitd3a61d5ec5357d19b7c0b6b599231e68dc5e237f (patch)
tree3a524935bba8d395abe40f16e744c75c35978627
parent027f62ec1860f4ab0c91bd863b238938880b8102 (diff)
Use VerifyIntegerConstantExpression for case values.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60317 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaStmt.cpp23
-rw-r--r--test/Sema/complex-int.c4
-rw-r--r--test/Sema/switch.c8
3 files changed, 10 insertions, 25 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 99fdbdb022..a469713121 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -126,31 +126,16 @@ Sema::ActOnCaseStmt(SourceLocation CaseLoc, ExprTy *lhsval,
Expr *LHSVal = ((Expr *)lhsval), *RHSVal = ((Expr *)rhsval);
assert((LHSVal != 0) && "missing expression in case statement");
- SourceLocation ExpLoc;
// C99 6.8.4.2p3: The expression shall be an integer constant.
// However, GCC allows any evaluatable integer expression.
- // FIXME: Should we warn if this is evaluatable but not an I-C-E?
- APValue Result;
- bool isEvaluated;
-
- if (!LHSVal->Evaluate(Result, Context, &isEvaluated) || !Result.isInt() ||
- !isEvaluated) {
- // FIXME: Evaluate doesn't return the SourceLocation that it failed to
- // evaluate.
- ExpLoc = LHSVal->getExprLoc();
- Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr)
- << LHSVal->getSourceRange();
+
+ if (VerifyIntegerConstantExpression(LHSVal))
return SubStmt;
- }
// GCC extension: The expression shall be an integer constant.
- if (RHSVal && !RHSVal->Evaluate(Result, Context, &isEvaluated) ||
- !Result.isInt() || !isEvaluated) {
- ExpLoc = RHSVal->getExprLoc();
- Diag(ExpLoc, diag::err_case_label_not_integer_constant_expr)
- << RHSVal->getSourceRange();
+
+ if (RHSVal && VerifyIntegerConstantExpression(RHSVal))
RHSVal = 0; // Recover by just forgetting about it.
- }
if (SwitchStack.empty()) {
Diag(CaseLoc, diag::err_case_not_in_switch);
diff --git a/test/Sema/complex-int.c b/test/Sema/complex-int.c
index 1e58b5320c..77bfc9c376 100644
--- a/test/Sema/complex-int.c
+++ b/test/Sema/complex-int.c
@@ -16,8 +16,8 @@ result = arr*brr;
result = xx*yy;
switch (arr) { // expected-error{{statement requires expression of integer type ('_Complex int' invalid)}}
- case brr: ; // expected-error{{case label does not reduce to an integer constant}}
- case xx: ; // expected-error{{case label does not reduce to an integer constant}}
+ case brr: ; // expected-error{{expression is not an integer constant expression}}
+ case xx: ; // expected-error{{expression is not an integer constant expression}}
}
}
diff --git a/test/Sema/switch.c b/test/Sema/switch.c
index 5886fefbd9..25e1d4d88a 100644
--- a/test/Sema/switch.c
+++ b/test/Sema/switch.c
@@ -39,8 +39,8 @@ void test4()
}
switch(1) {
- case g(): // expected-error {{case label does not reduce to an integer constant}}
- case 0 ... g(): // expected-error {{case label does not reduce to an integer constant}}
+ case g(): // expected-error {{expression is not an integer constant expression}}
+ case 0 ... g(): // expected-error {{expression is not an integer constant expression}}
break;
}
@@ -50,12 +50,12 @@ void test4()
}
switch (1) {
- case g() && 0: // expected-error {{case label does not reduce to an integer constant}}
+ case g() && 0: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}}
break;
}
switch (1) {
- case 0 ... g() || 1: // expected-error {{case label does not reduce to an integer constant}}
+ case 0 ... g() || 1: // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}}
break;
}
}