[cfe-commits] r60317 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/Sema/complex-int.c test/Sema/switch.c
Anders Carlsson
andersca at mac.com
Sun Nov 30 18:13:03 PST 2008
Author: andersca
Date: Sun Nov 30 20:13:02 2008
New Revision: 60317
URL: http://llvm.org/viewvc/llvm-project?rev=60317&view=rev
Log:
Use VerifyIntegerConstantExpression for case values.
Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/Sema/complex-int.c
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=60317&r1=60316&r2=60317&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Nov 30 20:13:02 2008
@@ -126,31 +126,16 @@
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);
Modified: cfe/trunk/test/Sema/complex-int.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/complex-int.c?rev=60317&r1=60316&r2=60317&view=diff
==============================================================================
--- cfe/trunk/test/Sema/complex-int.c (original)
+++ cfe/trunk/test/Sema/complex-int.c Sun Nov 30 20:13:02 2008
@@ -16,8 +16,8 @@
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}}
}
}
Modified: cfe/trunk/test/Sema/switch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/switch.c?rev=60317&r1=60316&r2=60317&view=diff
==============================================================================
--- cfe/trunk/test/Sema/switch.c (original)
+++ cfe/trunk/test/Sema/switch.c Sun Nov 30 20:13:02 2008
@@ -39,8 +39,8 @@
}
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 @@
}
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;
}
}
More information about the cfe-commits
mailing list