<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109095>109095</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang][C23] Crash when trying to use a `constexpr` variable that could not be initialized
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ianichitei
</td>
</tr>
</table>
<pre>
I don't think I chose the best title, but I don't know how else to describe it, but the code is pretty straight forward: https://godbolt.org/z/1Tj8ba5bq
```C
constexpr char c[] = { 'a' };
constexpr int i = c[1];
static_assert(i == c[0], "whatever");
```
When compiled with `-std=c23` with clang 19.1.0 this happens:
```
<source>:2:19: error: constexpr variable 'i' must be initialized by a constant expression
2 | constexpr int i = c[1];
| ^~~~
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-19.1.0/bin/clang -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c23 <source>
1. <eof> parser at end of file
#0 0x00000000036fdb08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x36fdb08)
#1 0x00000000036fbc74 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x36fbc74)
#2 0x0000000003647be8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000795267642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007952677aedcd (/lib/x86_64-linux-gnu/libc.so.6+0x1aedcd)
#5 0x0000000007257afd clang::Expr::getIntegerConstantExpr(clang::ASTContext const&, clang::SourceLocation*) const (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x7257afd)
#6 0x0000000006181049 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) (.constprop.0) SemaChecking.cpp:0:0
#7 0x00000000061833fa clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x61833fa)
#8 0x00000000066204e4 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x66204e4)
#9 0x0000000006385d7d clang::Sema::BuildStaticAssertDeclaration(clang::SourceLocation, clang::Expr*, clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x6385d7d)
#10 0x0000000005f81e36 clang::Parser::ParseStaticAssertDeclaration(clang::SourceLocation&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x5f81e36)
#11 0x0000000005f71028 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x5f71028)
#12 0x0000000005f27cfa clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x5f27cfa)
#13 0x0000000005f29ac8 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x5f29ac8)
#14 0x0000000005f1877a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x5f1877a)
#15 0x0000000003fce825 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x3fce825)
#16 0x0000000004274201 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x4274201)
#17 0x00000000041f699b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x41f699b)
#18 0x000000000435a843 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x435a843)
#19 0x0000000000c874dc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0xc874dc)
#20 0x0000000000c8146d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#21 0x0000000004017309 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
#22 0x0000000003648013 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x3648013)
#23 0x0000000004017529 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
#24 0x0000000003fdd947 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x3fdd947)
#25 0x0000000003fde2fd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x3fde2fd)
#26 0x0000000003fe7d4c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0x3fe7d4c)
#27 0x0000000000c847f1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+0xc847f1)
#28 0x0000000000b5c2d4 main (/opt/compiler-explorer/clang-19.1.0/bin/clang+0xb5c2d4)
#29 0x0000795267629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#30 0x0000795267629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#31 0x0000000000c80f0e _start (/opt/compiler-explorer/clang-19.1.0/bin/clang+0xc80f0e)
clang: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```
Weirdly enough, it looks like adding some other flags avoids the crash, for example with `-std=c23 -O3`: https://godbolt.org/z/41bGxqdh8 (it still crashes with `-O3 -std=c23`).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWU1z2zjS_jXwpYsqEqRE8uCDIkfzZipvJTVO7R5VIABKGEMABwBteQ7z27cAUh-QZScTa-eyqsSiyAb66aebjQaaWCvWivNbNP2Apnc3pHcbbW4FUYJuhOPiptHs-fYTMK0QLh24jVAP8AnoRlsObsOh4daBE05yhBfQ9A6O0g9KP8FGPwGXXloD45Ya0XAQbi_t56CacRAWOsOdewbrDBHrjYNWmydiGMrnsHGusyifI7xEeLnWrNHSTbRZI7z8E-Fl9u33qiHT5g-U3qF0Pv6dpcO_xfCbamUd33UG6IYYoIPVgPI7QOUHQLgkCJeAyjuUfzgfIpQDEWT9uAxNj0LWESfoiljLjUO4CmJ7ydRL4gUgjJ82xPFHbhDGCNeH4QeYp9j_veEKqN52QnIGT8JtAM3SxDqG8juKczRLh7tUErWGrJ5kk9T7x8KGdB1Xga1LZIw_84XVvaEc5R9RPscon2e1Z5obo42_OJr-SIwgjeSeIeEZ2vbWgXejEk4QKf7kDJpnIMMYohz4cdxaodWgDgAAAyoX8EOMQvh48ZcfNP34119_DXJfP3-c338E2zdb4YBA06_B8E4b58PtLGiE2_TNhOotwkspH_dfSWf075w6hJfC2p5bhJdAFAOhqOzZEObUELuBhtAHZwgNsd4Z3hlNubWcwc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