<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/90330>90330</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Crash issue when using flexible array member in struct S
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
iamanonymouscs
</td>
</tr>
</table>
<pre>
This crash can be observed in both LLVM 19 and LLVM trunk versions. (https://godbolt.org/z/d45oWKvaK)
# Command
`clang++ bug.cpp`
# Code
```cpp
struct S { char x[]; };
void
foo (struct S *x, struct S *y, struct S *z)
{
__atomic_exchange (x, y, z, __ATOMIC_SEQ_CST);
}
```
# Version
`clang --version`
```sh
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 987087df90026605fc8d03ebda5a1cd31b71e609)
Target: x86_64-unknown-linux-gnu
Thread model: posix
```
# Error Output
```sh
Stack dump:
0. Program arguments: /home/cTest/llvm-project/mybuild/bin/clang-19 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name code.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=/home/cTest -fcoverage-compilation-dir=/home/cTest -resource-dir /home/cTest/llvm-project/mybuild/lib/clang/19 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward -internal-isystem /home/cTest/llvm-project/mybuild/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/code-de3057.o -x c++ code.cpp
1. <eof> parser at end of file
2. code.cpp:4:1: LLVM IR generation of declaration 'foo'
3. code.cpp:4:1: Generating code for declaration 'foo'
#0 0x0000564525c79bcf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x37ddbcf)
#1 0x0000564525c773d4 SignalHandler(int) Signals.cpp:0:0
#2 0x00007efefd666420 __restore_rt (/usr/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x0000564526132f52 clang::CodeGen::CodeGenFunction::EmitAtomicExpr(clang::AtomicExpr*) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3c96f52)
#4 0x00005645263a6065 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#5 0x00005645263a74f7 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3f0b4f7)
#6 0x0000564526349bbe clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3eadbbe)
#7 0x0000564526364d23 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3ec8d23)
#8 0x0000564525f80b13 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3ae4b13)
#9 0x0000564525f86929 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3aea929)
#10 0x0000564525fe8fe3 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3b4cfe3)
#11 0x0000564525ff43c2 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3b583c2)
#12 0x000056452604f11d clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3bb311d)
#13 0x000056452604ab35 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3baeb35)
#14 0x000056452604b808 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x3baf808)
#15 0x0000564526053867 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#16 0x00005645264c635e (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#17 0x00005645264b7add clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x401badd)
#18 0x0000564527fd0534 clang::ParseAST(clang::Sema&, bool, bool) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x5b34534)
#19 0x00005645264c3b55 clang::CodeGenAction::ExecuteAction() (/home/cTest/llvm-project/mybuild/bin/clang-19+0x4027b55)
#20 0x0000564526755191 clang::FrontendAction::Execute() (/home/cTest/llvm-project/mybuild/bin/clang-19+0x42b9191)
#21 0x00005645266d04eb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x42344eb)
#22 0x000056452683511b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/cTest/llvm-project/mybuild/bin/clang-19+0x439911b)
#23 0x000056452338dced cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/cTest/llvm-project/mybuild/bin/clang-19+0xef1ced)
#24 0x000056452338657d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x000056452338ad96 clang_main(int, char**, llvm::ToolContext const&) (/home/cTest/llvm-project/mybuild/bin/clang-19+0xeeed96)
#26 0x0000564523290fdb main (/home/cTest/llvm-project/mybuild/bin/clang-19+0xdf4fdb)
#27 0x00007efefd114083 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#28 0x0000564523385d3e _start (/home/cTest/llvm-project/mybuild/bin/clang-19+0xee9d3e)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWVtz2zbT_jXwDQYaEuBBvPCFLFupp820X-1JLzUgsKTQkAAHBB25v_4bkDpBsZ3Y1fvOm4ltcQXsPs9iTyR536taA1yj9Aalt1d8cBtjrxVvuTb6uTVDL_qr0sjnaxTdomjxuFE9Fpb3Gyy4xiVgU_Zgn0BipXFp3Ab_9tuXzzguMNdy-uzsoL_iJ7C9MrqfYXS3QjdLNJ9vnOt6xBaIrhBd1UaWpnEzY2tEV_8gupJJav769Yn_ut9RTCAQZXhp2pZruRNkkWi4rhG9QfQGl0M9E12Hsmj39ckuCYct03-_cJT0zg7C4QeM8hssNtzi7eQVxG4wyv2fU3VPRu2sV8ZgROfH_XSxRXSJTwXP54J_EN2zyXd6MV6vuTOtEmvYig3XNXi9o65x_z_-13q9ePz98_1y_XD3f-vlw6PXc0CW356xO3fAl-kUQrdhQnanc9yxV9BvJsG0cLcMx8UsmkW1ch7g2TEqtxnKmTAtoqumedr_IZ01f4NwM7-rmOf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