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()) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits