[PATCH] D155548: [clang][ExprConst] Short-circuit ConstantExpr evaluation

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 17 23:24:30 PDT 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I think this makes sense to do, given that the `ConstantExpr`... is constant and can even already have the result attached.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155548

Files:
  clang/lib/AST/ExprConstant.cpp


Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15206,6 +15206,17 @@
     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()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155548.541329.patch
Type: text/x-patch
Size: 679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230718/7533d64f/attachment.bin>


More information about the cfe-commits mailing list