[clang] b4343ab - [clang][ExprConst] Short-circuit ConstantExpr evaluation
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 10 04:27:21 PDT 2023
Author: Timm Bäder
Date: 2023-10-10T13:27:03+02:00
New Revision: b4343aba9fa12ddb397e08208ec37fcf0fb93864
URL: https://github.com/llvm/llvm-project/commit/b4343aba9fa12ddb397e08208ec37fcf0fb93864
DIFF: https://github.com/llvm/llvm-project/commit/b4343aba9fa12ddb397e08208ec37fcf0fb93864.diff
LOG: [clang][ExprConst] Short-circuit ConstantExpr evaluation
ConstantExprs already have a value attached we can just return here.
Differential Revision: https://reviews.llvm.org/D155548
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5a33e918db8e8c0..e5539dedec02a4b 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15327,6 +15327,17 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
return true;
}
+ if (const auto *CE = dyn_cast<ConstantExpr>(Exp)) {
+ if (CE->hasAPValueResult()) {
+ Result.Val = CE->getAPValueResult();
+ IsConst = true;
+ return true;
+ }
+
+ // The SubExpr is usually just an IntegerLiteral.
+ return FastEvaluateAsRValue(CE->getSubExpr(), Result, Ctx, IsConst);
+ }
+
// This case should be rare, but we need to check it before we check on
// the type below.
if (Exp->getType().isNull()) {
More information about the cfe-commits
mailing list