Crash issue when using flexible array member in struct S (original) (raw)
This crash can be observed in both LLVM 19 and LLVM trunk versions. (https://godbolt.org/z/d45oWKvaK)
Command
clang++ bug.cpp
Code
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
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 987087df90026605fc8d03ebda5a1cd31b71e609) Target: x86_64-unknown-linux-gnu Thread model: posix
Error Output
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
<eof> parser at end of filecode.cpp:4:1: LLVM IR generation of declaration 'foo'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)