llvm / llvm/llvm-project

[codegen] Clang assertion `NumInitElements <= NumArrayElements` in CGExprAgg.cpp

Open
#213,069 4 comments 0 reactions 0 assignees View on GitHub
clang:frontend crash
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

https://godbolt.org/z/M594ndrxd
This input is the same as https://github.com/llvm/llvm-project/issues/154046. However, this time, it leads to a issue in codegen while that one is in frontend.

The assertion looks like https://github.com/llvm/llvm-project/issues/172974, but that one is in C++ and this is in C.
```cxx
#include
#include
#include
_Noreturn void handle_error(int code)
{
const char *msg = (const char[]) {
[0] = "Success",
[1] = "General error",
[2] = "Invalid input"
}[code];
fprintf(stderr, "Error: %s (%d)\n", msg ? msg : "Unknown", code);
exit(code);
}
int main(void)
{
volatile int state = 0;
int result = 0;
for (int i = 0; i < 3; ++i) {
if (signal(SIGINT, SIG_IGN) == SIG_ERR)
handle_error(2);
for (int j = i + 1; j < 5; ++j) {
state ^= j * (i + 1);
if (state % 3 == 0) {
result += abs(state - j);
continue;
}
else if (state % 2 == 0 && result > 0)
result /= 2;
else
result += state % 4;
}
}
printf("Final result: %d\n", result);
return result > 10 ? EXIT_FAILURE : EXIT_SUCCESS;
}
```
```
clang: /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGExprAgg.cpp:588: void {anonymous}::AggExprEmitter::EmitArrayInit(clang::CodeGen::Address, llvm::ArrayType*, clang::QualType, clang::Expr*, llvm::ArrayRef, clang::Expr*): Assertion `NumInitElements <= NumArrayElements' failed.
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 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O0 -std=c2x
1. :14:1: current parser token 'int'
2. :4:16: LLVM IR generation of declaration 'handle_error'
3. :4:16: Generating code for declaration 'handle_error'
#0 0x000000000441c478 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x441c478)
#1 0x0000000004419324 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4419324)
#2 0x000000000441995c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x441995c)
#3 0x0000000004358938 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007a36fa245330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x00007a36fa29eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x00007a36fa24527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007a36fa2288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x00007a36fa22881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x00007a36fa23b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000004920f87 (anonymous namespace)::AggExprEmitter::EmitArrayInit(clang::CodeGen::Address, llvm::ArrayType*, clang::QualType, clang::Expr*, llvm::ArrayRef, clang::Expr*) CGExprAgg.cpp:0:0
#11 0x0000000004927156 (anonymous namespace)::AggExprEmitter::VisitCXXParenListOrInitListExpr(clang::Expr*, llvm::ArrayRef, clang::FieldDecl*, clang::Expr*) CGExprAgg.cpp:0:0
#12 0x000000000492568b (anonymous namespace)::AggExprEmitter::Visit(clang::Expr*) CGExprAgg.cpp:0:0
#13 0x00000000049260be clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49260be)
#14 0x00000000048edc75 clang::CodeGen::CodeGenFunction::EmitAnyExprToMem(clang::Expr const*, clang::CodeGen::Address, clang::Qualifiers, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48edc75)
#15 0x00000000048ee05b clang::CodeGen::CodeGenFunction::EmitCompoundLiteralLValue(clang::CompoundLiteralExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48ee05b)
#16 0x0000000004915bfa clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4915bfa)
#17 0x0000000004915fe7 void llvm::function_ref::callback_fn(long) CGExpr.cpp:0:0
#18 0x0000000008865a91 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x8865a91)
#19 0x00000000048da13c clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48da13c)
#20 0x00000000049039b8 clang::CodeGen::CodeGenFunction::EmitArraySubscriptExpr(clang::ArraySubscriptExpr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49039b8)
#21 0x0000000004915c6e clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4915c6e)
#22 0x0000000004915fe7 void llvm::function_ref::callback_fn(long) CGExpr.cpp:0:0
#23 0x0000000008865a91 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x8865a91)
#24 0x00000000048da13c clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48da13c)
#25 0x0000000004901cde clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4901cde)
#26 0x000000000497e930 (anonymous namespace)::ScalarExprEmitter::EmitLoadOfLValue(clang::Expr const*) CGExprScalar.cpp:0:0
#27 0x000000000498310b (anonymous namespace)::ScalarExprEmitter::VisitArraySubscriptExpr(clang::ArraySubscriptExpr*) CGExprScalar.cpp:0:0
#28 0x000000000497894c clang::StmtVisitorBase::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#29 0x000000000497aabb (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#30 0x000000000497ee0b (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#31 0x0000000004978896 clang::StmtVisitorBase::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#32 0x000000000497aabb (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#33 0x0000000004980529 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#34 0x0000000004978896 clang::StmtVisitorBase::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#35 0x000000000497e2fc clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x497e2fc)
#36 0x0000000004e66019 clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4e66019)
#37 0x0000000004e67db7 clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4e67db7)
#38 0x0000000004e72018 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4e72018)
#39 0x0000000004e77419 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0
#40 0x0000000004e77c53 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4e77c53)
#41 0x0000000004a9732c clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a9732c)
#42 0x0000000004ab1137 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ab1137)
#43 0x0000000004aa8a78 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4aa8a78)
#44 0x0000000004ab0ceb clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ab0ceb)
#45 0x0000000004b19726 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b19726)
#46 0x0000000004b2efc4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b2efc4)
#47 0x0000000004b9f28a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b9f28a)
#48 0x0000000004b98614 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b98614)
#49 0x0000000004b98e03 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b98e03)
#50 0x0000000004ba64f9 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#51 0x0000000004f241e9 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#52 0x0000000004f15294 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f15294)
#53 0x0000000006d3a1d4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6d3a1d4)
#54 0x0000000004f22058 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f22058)
#55 0x000000000524f8a8 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x524f8a8)
#56 0x00000000051dc46d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x51dc46d)
#57 0x0000000005323ffd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5323ffd)
#58 0x0000000000dad0cc cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdad0cc)
#59 0x0000000000da3cea ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#60 0x0000000000da3e6d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#61 0x0000000004f99a89 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#62 0x0000000004358d74 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4358d74)
#63 0x0000000004f9a5f5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#64 0x0000000004f528a2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f528a2)
#65 0x0000000004f570d7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f570d7)
#66 0x0000000004f61635 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f61635)
#67 0x0000000000da95ca clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda95ca)
#68 0x0000000000cc50ca main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcc50ca)
#69 0x00007a36fa22a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#70 0x00007a36fa22a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#71 0x0000000000da3695 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda3695)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
ASM generation compiler returned: 134
:7:15: error: incompatible pointer to integer conversion initializing 'const char' with an expression of type 'char[8]' [-Wint-conversion]
7 | [0] = "Success",
| ^~~~~~~~~
:8:15: error: incompatible pointer to integer conversion initializing 'const char' with an expression of type 'char[14]' [-Wint-conversion]
8 | [1] = "General error",
| ^~~~~~~~~~~~~~~
:8:15: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
8 | [1] = "General error",
| ^~~~~~~~~~~~~~~
:7:15: note: previous initialization is here
7 | [0] = "Success",
| ^~~~~~~~~
:9:15: error: incompatible pointer to integer conversion initializing 'const char' with an expression of type 'char[14]' [-Wint-conversion]
9 | [2] = "Invalid input"
| ^~~~~~~~~~~~~~~
:9:15: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
9 | [2] = "Invalid input"
| ^~~~~~~~~~~~~~~
:7:15: note: previous initialization is here
7 | [0] = "Success",
| ^~~~~~~~~
:6:17: error: incompatible integer to pointer conversion initializing 'const char *' with an expression of type 'const char'; take the address with & [-Wint-conversion]
6 | const char *msg = (const char[]) {
| ^ ~~~~~~~~~~~~~~~~
| &
7 | [0] = "Success",
| ~~~~~~~~~~~~~~~~
8 | [1] = "General error",
| ~~~~~~~~~~~~~~~~~~~~~~
9 | [2] = "Invalid input"
| ~~~~~~~~~~~~~~~~~~~~~
10 | }[code];
| ~~~~~~~
clang-24: /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGExprAgg.cpp:588: void {anonymous}::AggExprEmitter::EmitArrayInit(clang::CodeGen::Address, llvm::ArrayType*, clang::QualType, clang::Expr*, llvm::ArrayRef, clang::Expr*): Assertion `NumInitElements <= NumArrayElements' failed.
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: /cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24 -cc1 -triple x86_64-unknown-linux-gnu -O0 -emit-obj -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -main-file-name example.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/lib/clang/24 -internal-isystem /cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/lib/clang/24/include -internal-isystem /cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/../include/x86_64-unknown-linux-gnu -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/17.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c2x -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -fdwarf2-cfi-asm -o /tmp/example-89a3b9.o -x c
1. :14:1: current parser token 'int'
2. :4:16: LLVM IR generation of declaration 'handle_error'
3. :4:16: Generating code for declaration 'handle_error'
#0 0x000000000441c478 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x441c478)
#1 0x0000000004419324 llvm::sys::RunSignalHandlers() (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4419324)
#2 0x000000000441949e SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x0000000004419548 SignalHandlerTerminate(int, siginfo_t*, void*) Signals.cpp:0:0
#4 0x0000791462e45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000791462e9eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x0000791462e4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x0000791462e288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x0000791462e2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x0000791462e3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x0000000004920f87 (anonymous namespace)::AggExprEmitter::EmitArrayInit(clang::CodeGen::Address, llvm::ArrayType*, clang::QualType, clang::Expr*, llvm::ArrayRef, clang::Expr*) CGExprAgg.cpp:0:0
#11 0x0000000004927156 (anonymous namespace)::AggExprEmitter::VisitCXXParenListOrInitListExpr(clang::Expr*, llvm::ArrayRef, clang::FieldDecl*, clang::Expr*) CGExprAgg.cpp:0:0
#12 0x000000000492568b (anonymous namespace)::AggExprEmitter::Visit(clang::Expr*) CGExprAgg.cpp:0:0
#13 0x00000000049260be clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x49260be)
#14 0x00000000048edc75 clang::CodeGen::CodeGenFunction::EmitAnyExprToMem(clang::Expr const*, clang::CodeGen::Address, clang::Qualifiers, bool) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x48edc75)
#15 0x00000000048ee05b clang::CodeGen::CodeGenFunction::EmitCompoundLiteralLValue(clang::CompoundLiteralExpr const*) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x48ee05b)
#16 0x0000000004915bfa clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4915bfa)
#17 0x0000000004915fe7 void llvm::function_ref::callback_fn(long) CGExpr.cpp:0:0
#18 0x0000000008865a91 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x8865a91)
#19 0x00000000048da13c clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x48da13c)
#20 0x00000000049039b8 clang::CodeGen::CodeGenFunction::EmitArraySubscriptExpr(clang::ArraySubscriptExpr const*, bool) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x49039b8)
#21 0x0000000004915c6e clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4915c6e)
#22 0x0000000004915fe7 void llvm::function_ref::callback_fn(long) CGExpr.cpp:0:0
#23 0x0000000008865a91 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x8865a91)
#24 0x00000000048da13c clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x48da13c)
#25 0x0000000004901cde clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*, clang::CodeGen::CodeGenFunction::TypeCheckKind) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4901cde)
#26 0x000000000497e930 (anonymous namespace)::ScalarExprEmitter::EmitLoadOfLValue(clang::Expr const*) CGExprScalar.cpp:0:0
#27 0x000000000498310b (anonymous namespace)::ScalarExprEmitter::VisitArraySubscriptExpr(clang::ArraySubscriptExpr*) CGExprScalar.cpp:0:0
#28 0x000000000497894c clang::StmtVisitorBase::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#29 0x000000000497aabb (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#30 0x000000000497ee0b (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#31 0x0000000004978896 clang::StmtVisitorBase::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#32 0x000000000497aabb (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#33 0x0000000004980529 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#34 0x0000000004978896 clang::StmtVisitorBase::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#35 0x000000000497e2fc clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x497e2fc)
#36 0x0000000004e66019 clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4e66019)
#37 0x0000000004e67db7 clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4e67db7)
#38 0x0000000004e72018 clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission const&) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4e72018)
#39 0x0000000004e77419 clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0
#40 0x0000000004e77c53 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&, bool) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4e77c53)
#41 0x0000000004a9732c clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4a9732c)
#42 0x0000000004ab1137 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4ab1137)
#43 0x0000000004aa8a78 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4aa8a78)
#44 0x0000000004ab0ceb clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4ab0ceb)
#45 0x0000000004b19726 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4b19726)
#46 0x0000000004b2efc4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4b2efc4)
#47 0x0000000004b9f28a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4b9f28a)
#48 0x0000000004b98614 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4b98614)
#49 0x0000000004b98e03 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4b98e03)
#50 0x0000000004ba64f9 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#51 0x0000000004f241e9 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#52 0x0000000004f15294 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4f15294)
#53 0x0000000006d3a1d4 clang::ParseAST(clang::Sema&, bool, bool) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x6d3a1d4)
#54 0x0000000004f22058 clang::CodeGenAction::ExecuteAction() (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x4f22058)
#55 0x000000000524f8a8 clang::FrontendAction::Execute() (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x524f8a8)
#56 0x00000000051dc46d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x51dc46d)
#57 0x0000000005323ffd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0x5323ffd)
#58 0x0000000000dad0cc cc1_main(llvm::ArrayRef, char const*, void*) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0xdad0cc)
#59 0x0000000000da3cea ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#60 0x0000000000da81eb clang_main(int, char**, llvm::ToolContext const&) (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0xda81eb)
#61 0x0000000000cc50ca main (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0xcc50ca)
#62 0x0000791462e2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#63 0x0000791462e2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#64 0x0000000000da3695 _start (/cefs/bc/bc56112621b493336dad6ad7_clang-assertions-trunk-20260730/bin/clang-24+0xda3695)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed with exit code -2 (use -v to see invocation)
Execution build compiler returned: 254
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with the provided C input using Clang at -O0 and -std=c2x. Start in clang/lib/CodeGen/CGExprAgg.cpp at AggExprEmitter::EmitArrayInit, then trace the compound literal and array-subscript code paths shown in the stack dump. Done means the input no longer triggers the NumInitElements assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.