[clang] [Clang] Avoid quadratic pack-indexing instantiation (store only the selected element) (PR #213790)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 6 02:28:11 PDT 2026


================
@@ -4638,7 +4638,11 @@ class PackIndexingExpr final
   Expr *getSelectedExpr() const {
     UnsignedOrNone Index = getSelectedIndex();
     assert(Index && "extracting the indexed expression of a dependant pack");
-    return getTrailingObjects()[*Index];
+    // Resolved nodes store only the selected expansion; unresolved nodes store
+    // the full list and are indexed by the evaluated index.
+    return getTrailingObjects()[PackIndexingExprBits.TransformedExpressions == 1
+                                    ? 0
+                                    : *Index];
----------------
cor3ntin wrote:

I think this is very brittle, I'd rather we store a bit saying we only store 1 expression.

https://github.com/llvm/llvm-project/pull/213790


More information about the cfe-commits mailing list