https://github.com/cor3ntin created https://github.com/llvm/llvm-project/pull/82234
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 >From 55eb380c43740d3ce6843f2ea5b4055b38104124 Mon Sep 17 00:00:00 2001 From: Corentin Jabot <corentinja...@gmail.com> Date: Mon, 19 Feb 2024 11:36:00 +0100 Subject: [PATCH] [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); +} + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits