Make VerifyIntegerConstantExpr print extension warnings for non-ICEs.
Overall, I'm not particularly happy with the current situation regarding
constant expression diagnostics, but I plan to improve it at some point.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70089 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index e7d5ee1..6e86e71 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4929,6 +4929,13 @@
}
bool Sema::VerifyIntegerConstantExpression(const Expr *E, llvm::APSInt *Result){
+ llvm::APSInt ICEResult;
+ if (E->isIntegerConstantExpr(ICEResult, Context)) {
+ if (Result)
+ *Result = ICEResult;
+ return false;
+ }
+
Expr::EvalResult EvalResult;
if (!E->Evaluate(EvalResult, Context) || !EvalResult.Val.isInt() ||
@@ -4946,14 +4953,12 @@
return true;
}
- if (EvalResult.Diag) {
- Diag(E->getExprLoc(), diag::ext_expr_not_ice) <<
- E->getSourceRange();
+ Diag(E->getExprLoc(), diag::ext_expr_not_ice) <<
+ E->getSourceRange();
- // Print the reason it's not a constant.
- if (Diags.getDiagnosticLevel(diag::ext_expr_not_ice) != Diagnostic::Ignored)
- Diag(EvalResult.DiagLoc, EvalResult.Diag);
- }
+ if (EvalResult.Diag &&
+ Diags.getDiagnosticLevel(diag::ext_expr_not_ice) != Diagnostic::Ignored)
+ Diag(EvalResult.DiagLoc, EvalResult.Diag);
if (Result)
*Result = EvalResult.Val.getInt();