diff options
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 41a4ae4..5f8ad18 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -14892,16 +14892,22 @@ bool Expr::isIntegerConstantExpr(const ASTContext &Ctx, return true; } -bool Expr::isIntegerConstantExpr(llvm::APSInt &Value, const ASTContext &Ctx, - SourceLocation *Loc, bool isEvaluated) const { +Optional<llvm::APSInt> Expr::getIntegerConstantExpr(const ASTContext &Ctx, + SourceLocation *Loc, + bool isEvaluated) const { assert(!isValueDependent() && "Expression evaluator can't be called on a dependent expression."); - if (Ctx.getLangOpts().CPlusPlus11) - return EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value, Loc); + APSInt Value; + + if (Ctx.getLangOpts().CPlusPlus11) { + if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value, Loc)) + return Value; + return None; + } if (!isIntegerConstantExpr(Ctx, Loc)) - return false; + return None; // The only possible side-effects here are due to UB discovered in the // evaluation (for instance, INT_MAX + 1). In such a case, we are still @@ -14915,8 +14921,7 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Value, const ASTContext &Ctx, if (!::EvaluateAsInt(this, ExprResult, Ctx, SE_AllowSideEffects, Info)) llvm_unreachable("ICE cannot be evaluated!"); - Value = ExprResult.Val.getInt(); - return true; + return ExprResult.Val.getInt(); } bool Expr::isCXX98IntegralConstantExpr(const ASTContext &Ctx) const { |