llvm / llvm/llvm-project

Clang 22 crash

Open
#192,807 2 comments 0 reactions 0 assignees View on GitHub
clang:codegen crash
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

The following code is crashing Clang 22:

```cpp
#include

enum class Enum
{
A, B, C
};

static constexpr auto my_tuple = std::make_tuple(
Enum::A, Enum::B, Enum::C
);

template
consteval auto test()
{
return [](std::index_sequence)
{
return ((std::get(my_tuple) == value) || ...);
}(std::make_index_sequence>());
}

constexpr auto global = test();
```

```
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: clang-22 -c test.cpp -std=c++20
1. parser at end of file
2. test.cpp:21:23: LLVM IR generation of declaration 'global'
3. test.cpp:21:23: Generating code for declaration 'global'
#0 0x00007b792a5c839f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-22/bin/../lib/libLLVM.so.22.1+0x4dc839f)
#1 0x00007b792a5c5c17 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-22/bin/../lib/libLLVM.so.22.1+0x4dc5c17)
#2 0x00007b792a4f34b7 (/usr/lib/llvm-22/bin/../lib/libLLVM.so.22.1+0x4cf34b7)
#3 0x00007b7925045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007b792a7998b8 llvm::Type::isIntegerTy(unsigned int) const (/usr/lib/llvm-22/bin/../lib/libLLVM.so.22.1+0x4f998b8)
#5 0x00007b793130137a clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2b0137a)
#6 0x00007b79310b4615 clang::CodeGen::CodeGenModule::EmitNullConstant(clang::QualType) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x28b4615)
#7 0x00007b793129b0a2 clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2a9b0a2)
#8 0x00007b793129304c clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2a9304c)
#9 0x00007b793129722b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2a9722b)
#10 0x00007b7931291daf clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2a91daf)
#11 0x00007b7931340e1c (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2b40e1c)
#12 0x00007b79312656d8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2a656d8)
#13 0x00007b792fd3e089 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x153e089)
#14 0x00007b7931a554f2 clang::FrontendAction::Execute() (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x32554f2)
#15 0x00007b79319cccf4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x31cccf4)
#16 0x00007b7931ae31aa clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x32e31aa)
#17 0x00005b73603a152d cc1_main(llvm::ArrayRef, char const*, void*) (/usr/lib/llvm-22/bin/clang+0x1352d)
#18 0x00005b736039e24a (/usr/lib/llvm-22/bin/clang+0x1024a)
#19 0x00005b736039fc70 (/usr/lib/llvm-22/bin/clang+0x11c70)
#20 0x00007b793168df52 (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2e8df52)
#21 0x00007b792a4f3137 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/usr/lib/llvm-22/bin/../lib/libLLVM.so.22.1+0x4cf3137)
#22 0x00007b793168d7a6 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2e8d7a6)
#23 0x00007b793164f6e2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2e4f6e2)
#24 0x00007b793164f8bf clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2e4f8bf)
#25 0x00007b7931670596 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/usr/lib/llvm-22/bin/../lib/libclang-cpp.so.22.1+0x2e70596)
#26 0x00005b736039dd2e clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-22/bin/clang+0xfd2e)
#27 0x00005b73603ac183 main (/usr/lib/llvm-22/bin/clang+0x1e183)
#28 0x00007b792502a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#29 0x00007b792502a28b call_init ./csu/../csu/libc-start.c:128:20
#30 0x00007b792502a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#31 0x00005b736039bf05 _start (/usr/lib/llvm-22/bin/clang+0xdf05)
clang-22: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 22.1.3 (++20260402073256+4250a0fc5de9-1~exp1~20260402073413.57)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-22/bin
```

```
# Crash reproducer for Ubuntu clang version 22.1.3 (++20260402073256+4250a0fc5de9-1~exp1~20260402073413.57)
# Driver args: "-c" "test.cpp" "-std=c++20"
# Original command: "/usr/lib/llvm-22/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/tmp" "-fcoverage-compilation-dir=/tmp" "-resource-dir" "/usr/lib/llvm-22/lib/clang/22" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward" "-internal-isystem" "/usr/lib/llvm-22/lib/clang/22/include" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-std=c++20" "-fdeprecated-macro" "-ferror-limit" "19" "-fmessage-length=235" "-fgnuc-version=4.2.1" "-fno-implicit-modules" "-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-fdwarf2-cfi-asm" "-o" "test.o" "-x" "c++" "test.cpp"
"/usr/lib/llvm-22/bin/clang" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/tmp" "-fcoverage-compilation-dir=/tmp" "-std=c++20" "-fdeprecated-macro" "-ferror-limit" "19" "-fmessage-length=235" "-fgnuc-version=4.2.1" "-fno-implicit-modules" "-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-faddrsig" "-fdwarf2-cfi-asm" "-x" "c++" "test-89481d.cpp"
```

This is also reproduceable on [Compiler Explorer](https://gcc.godbolt.org/z/ePcdWdGT4). Clang 21 and trunk both work fine.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.