diff options
author | Anders Carlsson <andersca@mac.com> | 2008-12-01 02:13:02 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-12-01 02:13:02 +0000 |
commit | d3a61d5ec5357d19b7c0b6b599231e68dc5e237f (patch) | |
tree | 3a524935bba8d395abe40f16e744c75c35978627 /lib/Sema/SemaStmt.cpp | |
parent | 027f62ec1860f4ab0c91bd863b238938880b8102 (diff) |
Use VerifyIntegerConstantExpression for case values.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60317 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 23 |
1 files changed, 4 insertions, 19 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); |