Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang crashes when attempting to initialise a constexpr static data member from a non-constexpr static member function template #84522

Open
cjdb opened this issue Mar 8, 2024 · 4 comments

Comments

@cjdb
Copy link
Contributor

cjdb commented Mar 8, 2024

Sample code

Both of the following snippets cause Clang to crash in isolation.

struct ClangCrasher {
  template <int...> static auto BuildMap() {}
  static constexpr auto value = BuildMap();
};
struct ClangCrasher {
  template <int...> static auto BuildMap() { return 0; }
  static constexpr auto value = BuildMap<>();
};

Diagnostic

Unexpected undeduced type!
UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CodeGenTypes.cpp:548!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-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++20 <source> -isystem/opt/compiler-explorer/libs/google-benchmark/trunk/include
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
 #0 0x00000000038ee468 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38ee468)
 #1 0x00000000038ec14c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38ec14c)
 #2 0x0000000003833fb8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f08d1242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f08d12969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007f08d1242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f08d12287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000000000383f24a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x383f24a)
 #8 0x0000000003d39cd3 clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d39cd3)
 #9 0x0000000003d3abd9 clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d3abd9)
#10 0x0000000003cc8651 clang::CodeGen::CodeGenModule::GetAddrOfGlobalVar(clang::VarDecl const*, llvm::Type*, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cc8651)
#11 0x0000000003cf1f3a clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cf1f3a)
#12 0x0000000003cf4e63 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cf4e63)
#13 0x00000000041869fa (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#14 0x000000000418551d clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x418551d)
#15 0x0000000006160d5c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6160d5c)
#16 0x0000000004184de8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4184de8)
#17 0x0000000004400319 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4400319)
#18 0x000000000437d84e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x437d84e)
#19 0x00000000044e246e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44e246e)
#20 0x0000000000c25566 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc25566)
#21 0x0000000000c1d2ca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#22 0x00000000041c64d9 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
#23 0x0000000003834464 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3834464)
#24 0x00000000041c6acf 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
#25 0x000000000418e675 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x418e675)
#26 0x000000000418f0dd 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+++0x418f0dd)
#27 0x0000000004197015 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4197015)
#28 0x0000000000c22a4d clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc22a4d)
#29 0x0000000000b17e04 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb17e04)
#30 0x00007f08d1229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#31 0x00007f08d1229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#32 0x0000000000c1cd8e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc1cd8e)

Compiler details

$ clang --version
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 0d4978f3cf8f917d88c19ec0ba3b1b3ef092cef1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-assertions-trunk-20240308/bin
@cjdb cjdb added clang Clang issues not falling into any other category crash-on-invalid labels Mar 8, 2024
@cjdb
Copy link
Contributor Author

cjdb commented Mar 8, 2024

Interestingly, this doesn't seem to fail when -fsyntax-only is enabled (which is worse, because it accepts an invalid program).

@EugeneZelenko EugeneZelenko added clang:codegen and removed clang Clang issues not falling into any other category labels Mar 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 8, 2024

@llvm/issue-subscribers-clang-codegen

Author: Christopher Di Bella (cjdb)

**Sample code**

Both of the following snippets cause Clang to crash in isolation.

struct ClangCrasher {
  template &lt;int...&gt; static auto BuildMap() {}
  static constexpr auto value = BuildMap();
};
struct ClangCrasher {
  template &lt;int...&gt; static auto BuildMap() { return 0; }
  static constexpr auto value = BuildMap&lt;&gt;();
};

Diagnostic

Unexpected undeduced type!
UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CodeGenTypes.cpp:548!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-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++20 &lt;source&gt; -isystem/opt/compiler-explorer/libs/google-benchmark/trunk/include
1.	&lt;eof&gt; parser at end of file
2.	Per-file LLVM IR generation
 #<!-- -->0 0x00000000038ee468 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38ee468)
 #<!-- -->1 0x00000000038ec14c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x38ec14c)
 #<!-- -->2 0x0000000003833fb8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #<!-- -->3 0x00007f08d1242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->4 0x00007f08d12969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #<!-- -->5 0x00007f08d1242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #<!-- -->6 0x00007f08d12287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #<!-- -->7 0x000000000383f24a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x383f24a)
 #<!-- -->8 0x0000000003d39cd3 clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d39cd3)
 #<!-- -->9 0x0000000003d3abd9 clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d3abd9)
#<!-- -->10 0x0000000003cc8651 clang::CodeGen::CodeGenModule::GetAddrOfGlobalVar(clang::VarDecl const*, llvm::Type*, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cc8651)
#<!-- -->11 0x0000000003cf1f3a clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cf1f3a)
#<!-- -->12 0x0000000003cf4e63 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3cf4e63)
#<!-- -->13 0x00000000041869fa (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&amp;) ModuleBuilder.cpp:0:0
#<!-- -->14 0x000000000418551d clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x418551d)
#<!-- -->15 0x0000000006160d5c clang::ParseAST(clang::Sema&amp;, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6160d5c)
#<!-- -->16 0x0000000004184de8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4184de8)
#<!-- -->17 0x0000000004400319 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4400319)
#<!-- -->18 0x000000000437d84e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x437d84e)
#<!-- -->19 0x00000000044e246e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44e246e)
#<!-- -->20 0x0000000000c25566 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc25566)
#<!-- -->21 0x0000000000c1d2ca ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->22 0x00000000041c64d9 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->23 0x0000000003834464 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3834464)
#<!-- -->24 0x00000000041c6acf clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->25 0x000000000418e675 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x418e675)
#<!-- -->26 0x000000000418f0dd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x418f0dd)
#<!-- -->27 0x0000000004197015 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4197015)
#<!-- -->28 0x0000000000c22a4d clang_main(int, char**, llvm::ToolContext const&amp;) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc22a4d)
#<!-- -->29 0x0000000000b17e04 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb17e04)
#<!-- -->30 0x00007f08d1229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->31 0x00007f08d1229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->32 0x0000000000c1cd8e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc1cd8e)

Compiler details

$ clang --version
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 0d4978f3cf8f917d88c19ec0ba3b1b3ef092cef1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-assertions-trunk-20240308/bin

@shafik
Copy link
Collaborator

shafik commented Mar 8, 2024

Looks related to: #49085

@cjdb
Copy link
Contributor Author

cjdb commented Mar 8, 2024

Ah, this also fails when BuildMap() is consteval, meaning that it crashes on valid code too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants