Author: LeeYoungJoon Date: 2026-07-02T16:21:55+09:00 New Revision: ad5add5fb62573fc1f139a40658d616e16a82625
URL: https://github.com/llvm/llvm-project/commit/ad5add5fb62573fc1f139a40658d616e16a82625 DIFF: https://github.com/llvm/llvm-project/commit/ad5add5fb62573fc1f139a40658d616e16a82625.diff LOG: [clang][serialization] Fix crash on imported pack indexing type (#205965) The selected index of a PackIndexingType was not serialized, so on deserialization its canonical type was rebuilt as a dependent type, crashing CodeGen. Difference in `Ty` during `CodeGenTypes::ConvertType` (https://github.com/llvm/llvm-project/blob/49cf5a7ba0ab76a1f700ce6407cea1713741bc01/clang/lib/CodeGen/CodeGenTypes.cpp#L415-L424) ### Before ```cpp PackIndexingType 0x142914680 'int' sugar |-SubstTemplateTypeParmPackType 0x1429145a0 'Ts' dependent contains_unexpanded_pack imported typename depth 0 index 0 ... Ts | |-TypeAliasTemplate 0x142914318 'element' | `-TemplateArgument pack '<int>' | `-TemplateArgument type 'int' | `-BuiltinType 0x14401cf10 'int' |-ConstantExpr 0x142914630 '__size_t':'unsigned long' | |-value: Int 0 | `-ImplicitCastExpr 0x1429145f0 '__size_t':'unsigned long' <IntegralCast> | `-IntegerLiteral 0x1429145d0 'int' 0 `-SubstTemplateTypeParmType 0x142914650 'int' sugar imported typename depth 0 index 0 ... Ts pack_index 0 final |-TypeAliasTemplate 0x142914318 'element' `-BuiltinType 0x14401cf10 'int' ``` ### After ```cpp BuiltinType 0x14e02e710 'int' ``` I used AI assistance when writing the test code, but I personally reviewed it. 🤖 Fixes https://github.com/llvm/llvm-project/issues/204479 --------- Co-authored-by: Younan Zhang <[email protected]> Added: clang/test/Modules/pr204479.cppm Modified: clang/docs/ReleaseNotes.md clang/include/clang/AST/TypeProperties.td Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index af80d8b9d0495..21b2d10d05bc1 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -830,6 +830,7 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the - 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 an assertion failure during init-list checking of an array whose element type is an incomplete class. (#GH140685) +- 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/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); }]>; } diff --git a/clang/test/Modules/pr204479.cppm b/clang/test/Modules/pr204479.cppm new file mode 100644 index 0000000000000..8a636aed9cf17 --- /dev/null +++ b/clang/test/Modules/pr204479.cppm @@ -0,0 +1,24 @@ +// 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.cppm +export module a; + +template<typename... Ts> +using element = Ts...[0]; + +export element<int> a = 0; + +//--- b.cpp +import a; + +int b() { + return a; +} + +// 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
