forked from OSchip/llvm-project
Use VerifyIntegerConstantExpression for case values.
llvm-svn: 60317
This commit is contained in:
parent
564730a857
commit
f7fba46331
|
@ -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);
|
||||
|
|
|
@ -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}}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue