[clang] b504803 - [clang] fix profiling of pack index expressions (#192810)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 20 07:49:37 PDT 2026


Author: Matheus Izvekov
Date: 2026-04-20T14:49:32Z
New Revision: b5048038ef7c8c344d49b0bfe5b5d32db45ed8f3

URL: https://github.com/llvm/llvm-project/commit/b5048038ef7c8c344d49b0bfe5b5d32db45ed8f3
DIFF: https://github.com/llvm/llvm-project/commit/b5048038ef7c8c344d49b0bfe5b5d32db45ed8f3.diff

LOG: [clang] fix profiling of pack index expressions (#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.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/AST/StmtProfile.cpp
    clang/test/SemaCXX/cxx2c-pack-indexing.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e89c73fbade58..e6bcae8256365 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -478,7 +478,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 cfe-commits mailing list