<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/86279>86279</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++26] Crash when indexing a pack with a pack of indices
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kaimfrai
</td>
</tr>
</table>
<pre>
The following code crashes on the most recent clang trunk when compiling with `-std=c++2c`.
The intent is to transform a pack of types into two sub-packs using the new pack indexing feature in C++26.
```
#include <utility>
template<typename... T>
struct TypeList{};
template<typename... T, std::size_t... left, std::size_t... right>
auto SplitImpl(TypeList<T...>, std::index_sequence<left...>, std::index_sequence<right...>)
{
return TypeList<TypeList<T...[left]...>, TypeList<T...[sizeof...(left) + right]...>>{};
}
template<std::size_t N, typename... T>
auto Split(TypeList<T...> tl)
{
return SplitImpl(tl, std::make_index_sequence<N>{}, std::make_index_sequence<sizeof...(T) - N>{});
}
auto tl1 = TypeList<char, bool, float, int, double>{};
auto tl2 = Split<2>(tl1);
```
https://godbolt.org/z/Px5c5971o
```
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++2c <source>
1. <eof> parser at end of file
2. <source>:19:6: LLVM IR generation of declaration 'tl2'
3. <source>:19:6: Generating code for declaration 'tl2'
#0 0x0000000003695e68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3695e68)
#1 0x0000000003693fb4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3693fb4)
#2 0x00000000035dd148 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f3b03e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00000000030aa562 llvm::Type::isIntegerTy(unsigned int) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x30aa562)
#5 0x0000000003aaf7a5 clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3aaf7a5)
#6 0x000000000397a5dd clang::CodeGen::CodeGenModule::EmitNullConstant(clang::QualType) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x397a5dd)
#7 0x0000000003a3f3fa clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a3f3fa)
#8 0x0000000003a62f45 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a62f45)
#9 0x0000000003a635f3 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3a635f3)
#10 0x0000000003a6bdd7 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#11 0x0000000003ef1e4e (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#12 0x0000000003ee2fb9 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3ee2fb9)
#13 0x0000000005da18e4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x5da18e4)
#14 0x0000000003eef935 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3eef935)
#15 0x0000000004186c01 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4186c01)
#16 0x000000000410c99b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x410c99b)
#17 0x0000000004269503 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4269503)
#18 0x0000000000c33a4c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc33a4c)
#19 0x0000000000c2d9fd ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#20 0x0000000003f38799 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#21 0x00000000035dd573 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x35dd573)
#22 0x0000000003f389b9 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#23 0x0000000003efef77 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3efef77)
#24 0x0000000003eff92d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3eff92d)
#25 0x0000000003f0974c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3f0974c)
#26 0x0000000000c30eb1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc30eb1)
#27 0x0000000000b28884 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xb28884)
#28 0x00007f3b03e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#29 0x00007f3b03e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#30 0x0000000000c2d55e _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc2d55e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWU9z27oR_zTwBUMNCUr8c_BBluI0b5I0jT25akBwKaEGARYAbfl9-g5ASiZk2Ule1V6aiW0JXOz-9ofF7hKgxvCtBLhGixu0WF_R3u6Uvn6gvG005VeVqp-v73eAGyWEeuJyi5mqATNNzQ4MVhLbHeBWGYs1MJAWM0HlFlvdywf8tAOJmWo7LtzUJ253GGVxZGyN0jVD5AaRG8JQFs8witcoXjpbXFqniBtsFbaaStMo3WKKO8oesGqwfe7AODGF7ZPCpq8i98jg3jgzDpGEp0Gcyxr2brQBanvttOPVaDibDUbH31k8_h--kpRLJvoaMEpXveWC22eUfphOsdB2glpA6cphkrSF2WyG749ixuqeWXz_3MFnbizKb1C-RunNLykhK-yJWqJ0afifsLFuXEBj33ik-XZnj7ZpbxW-6wS3n9pOIFIcUaSr-9ls5gSnejxTGwP_6kEyh8ZZ-hU5b_YgWI6u5aOPWIPttcRT4yc4Fjfep8X6xdhrEeelatxnUgwUlBiRm9Hn49z0wynH-foNsk8IxF-d4fPL-ELlWRqxFWccx_jg-3QRnOiEzJY-wOYVo19f_Pi58JSZe0dLhKfzy7eo8E5ZkWCUrqeEsx3VzmyllMfaCEV9xHHp_9SqrwS8ZnrUR7y-gax0RfyCFlYkAZKTreZ_76ztjHOU3CJyu1V1pYSdKb1F5PZPRG6_7RdsUeaJemfT3lm35-u-7ZwiPxTPUFx-02qraYup3vYtSOvsYERuVWcRuR0yFOgI9p1QGrQbc2ks8mkMkduKy8P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