https://github.com/IamYJLee updated https://github.com/llvm/llvm-project/pull/205965
>From e4e0af6e75a56918530aaf31c6024de7cdb1c09a Mon Sep 17 00:00:00 2001 From: LeeYoungJoon <[email protected]> Date: Fri, 26 Jun 2026 12:39:01 +0900 Subject: [PATCH 1/2] [clang][ast] Add an index property for PackIndexingType serialization --- clang/include/clang/AST/TypeProperties.td | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/AST/TypeProperties.td b/clang/include/clang/AST/TypeProperties.td index f16c10da430f9..e2168d0a00ff4 100644 --- a/clang/include/clang/AST/TypeProperties.td +++ b/clang/include/clang/AST/TypeProperties.td @@ -489,9 +489,12 @@ let Class = PackIndexingType in { def : Property<"expansions", Array<QualType>> { let Read = [{ node->getExpansions() }]; } + def : Property<"index", UnsignedOrNone> { + let Read = [{ node->getSelectedIndex() }]; + } def : Creator<[{ - return ctx.getPackIndexingType(pattern, indexExpression, isFullySubstituted, expansions); + return ctx.getPackIndexingType(pattern, indexExpression, isFullySubstituted, expansions, index); }]>; } >From ff931c9c8d399a1c7e4c45e9b12d45b52ef1e483 Mon Sep 17 00:00:00 2001 From: LeeYoungJoon <[email protected]> Date: Mon, 29 Jun 2026 11:28:03 +0900 Subject: [PATCH 2/2] Add testcase and release note --- clang/docs/ReleaseNotes.rst | 1 + clang/test/Modules/pack-indexing.cpp | 31 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 clang/test/Modules/pack-indexing.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index a2439ccb0452a..53b57666e0f87 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -816,6 +816,7 @@ Bug Fixes to C++ Support - Fixed an issue where Clang incorrectly accepted invalid unqualified uses of local nested class names outside their declaring scope. (#GH184622) - Fixed a crash when parsing invalid friend declaration with storage-class specifier. (#GH186569) - Fixed a missing vtable for ``dynamic_cast<FinalClass *>(this)`` in a function template. (#GH198511) +- Fixed a crash when using a pack indexing type (e.g. ``Ts...[0]``) imported from another module. (#GH204479) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/test/Modules/pack-indexing.cpp b/clang/test/Modules/pack-indexing.cpp new file mode 100644 index 0000000000000..1908f535577a3 --- /dev/null +++ b/clang/test/Modules/pack-indexing.cpp @@ -0,0 +1,31 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t +// +// RUN: %clang_cc1 -std=c++26 -triple %itanium_abi_triple -emit-module-interface %t/a.cppm -o %t/a.pcm +// RUN: %clang_cc1 -std=c++26 -triple %itanium_abi_triple -fmodule-file=a=%t/a.pcm -emit-llvm -o - %t/b.cpp | FileCheck %s + +// A fully-substituted pack indexing type (`Ts...[0]`) exported through a module +// used to lose its selected index on deserialization, so its canonical type was +// rebuilt as a dependent PackIndexingType. CodeGen then hit +// llvm_unreachable("Non-canonical or dependent types aren't possible."). + +//--- a.cppm +export module a; + +template<typename... Ts> +using element = Ts...[0]; + +export element<int> a = 0; + +//--- b.cpp +import a; + +int b() { + return a; +} + +// The pack indexing type `element<int>` must be lowered to `i32` without +// crashing in CodeGen. +// CHECK: @_ZW1a1a = external global i32 +// CHECK: define {{.*}}i32 @_Z1bv() +// CHECK: load i32, ptr @_ZW1a1a _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
