-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Open
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.confirmedVerified by a second partyVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]
Description
Put
int foo(void);
int bar(void) {
return sizeof *(1 ? 0 : (char (*)[foo()]) 0);
}
In a file named x.c and execute “clang -c x.c”.
This results in a crash. Output copied from Compiler Explorer (https://godbolt.org/z/bW6xvse7v) is:
Could not execute the program
Compiler returned: 254
Compiler stderr
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-trunk-20221115/bin/clang-16 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -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 -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-trunk-20221115/lib/clang/16 -internal-isystem /opt/compiler-explorer/clang-trunk-20221115/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/app -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-850648.o -x c <source>
1. <eof> parser at end of file
2. <source>:1:20: LLVM IR generation of declaration 'bar'
3. <source>:1:20: Generating code for declaration 'bar'
#0 0x0000564afefad024 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x0000564afefaa8a4 SignalHandler(int) Signals.cpp:0:0
#2 0x00007fe307810420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x0000564aff7c69e2 (anonymous namespace)::ScalarExprEmitter::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation, (anonymous namespace)::ScalarExprEmitter::ScalarConversionOpts) CGExprScalar.cpp:0:0
#4 0x0000564aff7d8af9 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#5 0x0000564aff7d21ba (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#6 0x0000564aff7d3fb7 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x42a6fb7)
#7 0x0000564aff3ffe04 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x3ed2e04)
#8 0x0000564aff401d35 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x3ed4d35)
#9 0x0000564aff407d9a clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x3edad9a)
#10 0x0000564aff46668d clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x3f3968d)
#11 0x0000564aff471c16 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x3f44c16)
#12 0x0000564aff4c81ba clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x3f9b1ba)
#13 0x0000564aff4c4965 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x3f97965)
#14 0x0000564aff4c4e53 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x3f97e53)
#15 0x0000564aff4cc5fa clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#16 0x0000564b0023b2b1 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#17 0x0000564b0022ddcd clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x4d00dcd)
#18 0x0000564b0143a074 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x5f0d074)
#19 0x0000564b00238e15 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x4d0be15)
#20 0x0000564affb39471 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x460c471)
#21 0x0000564affabe103 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x4591103)
#22 0x0000564affc1cdab clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x46efdab)
#23 0x0000564afc813afc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x12e6afc)
#24 0x0000564afc80eebc ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#25 0x0000564afc80f4df clang_main(int, char**) (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x12e24df)
#26 0x00007fe3072be083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#27 0x0000564afc80bb3e _start (/opt/compiler-explorer/clang-trunk-20221115/bin/clang-16+0x12deb3e)
clang-16: error: unable to execute command: Segmentation fault (core dumped)
clang-16: error: clang frontend command failed due to signal (use -v to see invocation)
This appears to involve an omission in the C standard. For “1 ? 0 : (char (*)[foo()]) 0)”, the standard says the type of the conditional expression is the type of the third operand (because the second operand is a null pointer constant), but it is not evaluated, so the type is a variable length array whose length is not evaluated.
I do not have access to Compiler Explorer’s files to provide the requested script to replay Clang, sorry, but this seems easily reproducible. (On my own system, I use Apple Clang and have reported it separately to Apple.)
Metadata
Metadata
Assignees
Labels
clang:codegenIR generation bugs: mangling, exceptions, etc.IR generation bugs: mangling, exceptions, etc.confirmedVerified by a second partyVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]