[llvm-branch-commits] [clang] [clang] fix profiling of pack index expressions (PR #192810)

Matheus Izvekov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Apr 18 13:36:23 PDT 2026


https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/192810

This replaces a few incorrect calls of VisitExpr on subcomponents, which should have been plain `Visit` instead, because the former just implements the commonality between all kind-specific profile functions (marking the class kind and visiting children).

So this for example would visit a DeclRefExpr but not actually profile any of it's properties, like the parameter declaration, so it would fail to distinguish between DeclRefExps referencing distinct entities.

This also adds a call to record the PackIndexExpr's kind in the profile, to avoid false positives when comparing expressions with different kinds.

>From 28e6b46d6b7857fca7bc8fdcccc2c2ec9891ae36 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov <mizvekov at gmail.com>
Date: Sat, 18 Apr 2026 17:28:29 -0300
Subject: [PATCH] [clang] fix profiling of pack index expressions

This replaces a few incorrect calls of VisitExpr on subcomponents,
which should have been plain `Visit` instead, because the former
just implements the commonality between all kind-specific profile
functions (marking the class kind and visiting children).

So this for example would visit a DeclRefExpr but not actually profile
any of it's properties, like the parameter declaration, so it would fail
to distinguish between DeclRefExps referencing distinct entities.

This also adds a call to record the PackIndexExpr's kind in the profile,
to avoid false positives when comparing expressions with different kinds.
---
 clang/docs/ReleaseNotes.rst                |  3 ++-
 clang/lib/AST/StmtProfile.cpp              |  6 +++---
 clang/test/SemaCXX/cxx2c-pack-indexing.cpp | 10 ++++++++++
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 87512f8f6097a..4ed92f9c1afd1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -441,7 +441,8 @@ Bug Fixes to C++ Support
 - Fixed a bug matching constrained out-of-line definitions of class members.
 - Fixed a crash when instantiating an invalid out-of-line static data member definition in a local class. (#GH176152)
 - Fixed a crash when pack expansions are used as arguments for non-pack parameters of built-in templates. (#GH180307)
-- Fixed a bug where captured variables in non-mutable lambdas were incorrectly treated as mutable 
+- Fix a problem where pack index expressions where incorrectly being regarded as equivalent.
+- Fixed a bug where captured variables in non-mutable lambdas were incorrectly treated as mutable
   when used inside decltype in the return type. (#GH180460)
 - Fixed a crash when evaluating uninitialized GCC vector/ext_vector_type vectors in ``constexpr``. (#GH180044)
 - Fixed a crash when `explicit(bool)` is used with an incomplete enumeration. (#GH183887)
diff --git a/clang/lib/AST/StmtProfile.cpp b/clang/lib/AST/StmtProfile.cpp
index bd65f20214791..e71f6da8393f2 100644
--- a/clang/lib/AST/StmtProfile.cpp
+++ b/clang/lib/AST/StmtProfile.cpp
@@ -2362,14 +2362,14 @@ void StmtProfiler::VisitSizeOfPackExpr(const SizeOfPackExpr *S) {
 }
 
 void StmtProfiler::VisitPackIndexingExpr(const PackIndexingExpr *E) {
-  VisitExpr(E->getIndexExpr());
-
+  VisitStmtNoChildren(E);
+  Visit(E->getIndexExpr());
   if (E->expandsToEmptyPack() || E->getExpressions().size() != 0) {
     ID.AddInteger(E->getExpressions().size());
     for (const Expr *Sub : E->getExpressions())
       Visit(Sub);
   } else {
-    VisitExpr(E->getPackIdExpression());
+    Visit(E->getPackIdExpression());
   }
 }
 
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index 0e759a01375de..86d17be4f72b7 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -344,3 +344,13 @@ namespace GH123033 {
       convert<int, int>(12.34);
   }
 }
+
+namespace PackIndexExprEquivalency1 {
+  template <int... Ts, int... Us>
+    requires (Ts...[0] != 0)
+    void f() {}
+
+  template <int... Ts, int... Us>
+    requires (Us...[0] != 0)
+    void f() {}
+} // namespace PackIndexExprEquivalency1



More information about the llvm-branch-commits mailing list