Issue 204479
Summary [clang] Crash when using exported entitity defined with pack indexing
Labels clang:modules, crash
Assignees
Reporter davidstone
    Given the following valid translation units:

```c++
export module a;

template<typename... Ts>
using element = Ts...[0];

export element<int> a = 0;
```

```c++
import a;

void b() {
	a;
}
```

clang crashes with

```console
Step cmake returned: 0
-- The CXX compiler identification is Clang 23.0.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /app/build
Step build returned: 1
[1/6] Scanning /app/a.cpp for CXX dependencies
[2/6] Scanning /app/b.cpp for CXX dependencies
[3/6] Generating CXX dyndep file CMakeFiles/bug.dir/CXX.dd
[4/6] Building CXX object CMakeFiles/bug.dir/a.cpp.o
[5/6] Building CXX object CMakeFiles/bug.dir/b.cpp.o
FAILED: CMakeFiles/bug.dir/b.cpp.o 
/opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot   -fcolor-diagnostics -fno-crash-diagnostics -w -g -std=c++26 -MD -MT CMakeFiles/bug.dir/b.cpp.o -MF CMakeFiles/bug.dir/b.cpp.o.d @CMakeFiles/bug.dir/b.cpp.o.modmap -o CMakeFiles/bug.dir/b.cpp.o -c /app/b.cpp
Non-canonical or dependent types aren't possible.
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/CodeGen/CodeGenTypes.cpp:423!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -w -g -std=c++26 -MD -MT CMakeFiles/bug.dir/b.cpp.o -MF CMakeFiles/bug.dir/b.cpp.o.d @CMakeFiles/bug.dir/b.cpp.o.modmap -o CMakeFiles/bug.dir/b.cpp.o -c /app/b.cpp
1.	<eof> parser at end of file
2.	/app/b.cpp:3:6: LLVM IR generation of declaration 'b'
3.	/app/b.cpp:3:6: Generating code for declaration 'b'
 #0 0x0000000004349ff8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4349ff8)
 #1 0x0000000004346f34 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4346f34)
 #2 0x0000000004347554 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4347554)
 #3 0x0000000004284a98 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #4 0x0000701410e45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #5 0x0000701410e9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
 #6 0x0000701410e4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #7 0x0000701410e288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #8 0x000000000428ee3a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x428ee3a)
 #9 0x0000000004b10e11 clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b10e11)
#10 0x0000000004b11d45 clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b11d45)
#11 0x0000000004a91828 clang::CodeGen::CodeGenModule::GetAddrOfGlobalVar(clang::VarDecl const*, llvm::Type*, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a91828)
#12 0x0000000004817153 clang::CodeGen::CodeGenFunction::EmitDeclRefLValue(clang::DeclRefExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4817153)
#13 0x00000000048361fe clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48361fe)
#14 0x0000000004836797 void llvm::function_ref<void ()>::callback_fn<clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t)::'lambda'()>(long) CGExpr.cpp:0:0
#15 0x000000000870d931 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x870d931)
#16 0x00000000047fc13c clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47fc13c)
#17 0x000000000482e6fe clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x482e6fe)
#18 0x00000000049c7931 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49c7931)
#19 0x00000000049cf63b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49cf63b)
#20 0x0000000004a38a76 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a38a76)
#21 0x0000000004a4e824 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a4e824)
#22 0x0000000004abd7ca clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4abd7ca)
#23 0x0000000004ab7d94 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ab7d94)
#24 0x0000000004ab8583 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ab8583)
#25 0x0000000004ac4ac3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#26 0x0000000004e42c39 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#27 0x0000000004e33154 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e33154)
#28 0x0000000006bfb864 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6bfb864)
#29 0x0000000004e409c8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e409c8)
#30 0x0000000005178b58 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5178b58)
#31 0x00000000050f49ed clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50f49ed)
#32 0x000000000527796d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x527796d)
#33 0x0000000000dcebdc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdcebdc)
#34 0x0000000000dc58ba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#35 0x0000000000dc5a3d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#36 0x0000000004eb35e9 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
#37 0x0000000004284ed4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4284ed4)
#38 0x0000000004eb3c36 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
#39 0x0000000004e705d2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e705d2)
#40 0x0000000004e7157e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e7157e)
#41 0x0000000004e78db5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e78db5)
#42 0x0000000000dcb152 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdcb152)
#43 0x0000000000ccae0a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xccae0a)
#44 0x0000701410e2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#45 0x0000701410e2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#46 0x0000000000dc5265 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc5265)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Aborted (core dumped)
ninja: build stopped: subcommand failed.
```

See it live: https://godbolt.org/z/4vdncsjdn
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to