diff options
author | David Blaikie <dblaikie@gmail.com> | 2020-07-12 20:31:08 -0700 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2020-07-21 20:57:12 -0700 |
commit | 36036aa70ec1df7b51b5d30b2dd8090ad2b6e783 (patch) | |
tree | 75802c77ce4b3d29be9bbcf192bdffe255932b70 /clang/lib/AST/ExprConstant.cpp | |
parent | e4ef948a434325fc12a16dcacf513fbd9390eb06 (diff) | |
download | llvm-36036aa70ec1df7b51b5d30b2dd8090ad2b6e783.zip llvm-36036aa70ec1df7b51b5d30b2dd8090ad2b6e783.tar.gz llvm-36036aa70ec1df7b51b5d30b2dd8090ad2b6e783.tar.bz2 |
Reapply "Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression"
Reapply 49e5f603d40083dce9c05796e3cde3a185c3beba
which had been reverted in c94332919bd922032e979b3ae3ced5ca5bdf9650.
Originally reverted because I hadn't updated it in quite a while when I
got around to committing it, so there were a bunch of missing changes to
new code since I'd written the patch.
Reviewers: aaron.ballman
Differential Revision: https://reviews.llvm.org/D76646
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 { |