[clang] [Clang] Fix assert when transforming a pack indexing type. (PR #82234)

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 19 02:45:46 PST 2024


https://github.com/cor3ntin updated https://github.com/llvm/llvm-project/pull/82234

>From 55eb380c43740d3ce6843f2ea5b4055b38104124 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Mon, 19 Feb 2024 11:36:00 +0100
Subject: [PATCH 1/2] [Clang] Fix assert when transforming a pack indexing
 type.

When a pack in a pack indexing specifier cannot be immediately
expanded, we were creating an incomplete TypeLoc
(causing assertion failure).

As we do not keep track of typelocs of expanded elements,
we create a trivial typeloc

Fixes #81697
---
 clang/lib/Sema/TreeTransform.h             |  4 +++-
 clang/test/SemaCXX/cxx2c-pack-indexing.cpp | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index a32a585531873a..964ddeefc5a088 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6561,7 +6561,9 @@ TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
       return QualType();
     if (!ShouldExpand) {
       Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
-      QualType Pack = getDerived().TransformType(T);
+      // FIXME: should we keep TypeLoc for individual expansions in PackIndexingTypeLoc?
+      TypeSourceInfo* TI = SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
+      QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
       if (Pack.isNull())
         return QualType();
       if (NotYetExpanded) {
diff --git a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
index 625a56031598b7..e13635383b6ca6 100644
--- a/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
+++ b/clang/test/SemaCXX/cxx2c-pack-indexing.cpp
@@ -135,3 +135,22 @@ using Splice = typename SpliceImpl<Tl, Il>::type;
 using type = Splice<TL<char, short, long, double>, IL<1, 2>>;
 static_assert(is_same<type, TL<short, long>>);
 }
+
+
+namespace GH81697 {
+
+template<class... Ts> struct tuple {
+    int __x0;
+};
+
+template<auto I, class... Ts>
+Ts...[I]& get(tuple<Ts...>& t) {
+  return t.__x0;
+}
+
+void f() {
+  tuple<int> x;
+  get<0>(x);
+}
+
+}

>From 579f41b6d37c9bf98a57994d382391616d97d014 Mon Sep 17 00:00:00 2001
From: Corentin Jabot <corentinjabot at gmail.com>
Date: Mon, 19 Feb 2024 11:45:32 +0100
Subject: [PATCH 2/2] clang format

---
 clang/lib/Sema/TreeTransform.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 964ddeefc5a088..7389a48fe56fcc 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6561,8 +6561,10 @@ TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
       return QualType();
     if (!ShouldExpand) {
       Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
-      // FIXME: should we keep TypeLoc for individual expansions in PackIndexingTypeLoc?
-      TypeSourceInfo* TI = SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
+      // FIXME: should we keep TypeLoc for individual expansions in
+      // PackIndexingTypeLoc?
+      TypeSourceInfo *TI =
+          SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
       QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
       if (Pack.isNull())
         return QualType();



More information about the cfe-commits mailing list