Open
Description
This testcase is generated by a fuzzer.
Compiler Explorer: https://godbolt.org/z/GPhW5Y88M
This valid code will crash on clang assertion trunk:
__complex double foo() {
__complex double f;
return (__builtin_constant_p(f) ? f : 0);
}
It seems that this goes back to clang-10.
Stack dump:
clang++: /root/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:5577: llvm::Value* clang::CodeGen::CodeGenFunction::EmitScalarExpr(const clang::Expr*, bool): Assertion `E && hasScalarEvaluationKind(E->getType()) && "Invalid scalar expression to emit"' failed.
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-assertions-trunk/bin/clang++ -gdwarf-4 -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 <source>
1. <eof> parser at end of file
2. <source>:1:18: LLVM IR generation of declaration 'foo'
3. <source>:1:18: Generating code for declaration 'foo'
#0 0x0000000003c04df8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c04df8)
#1 0x0000000003c02b04 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3c02b04)
#2 0x0000000003b50068 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007a4613642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007a46136969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007a4613642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007a46136287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007a461362871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007a4613639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x000000000445b3d4 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x445b3d4)
#10 0x000000000433703b clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(clang::GlobalDecl, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x433703b)
#11 0x00000000044098de clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44098de)
#12 0x0000000004461604 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#13 0x000000000445576b clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#14 0x000000000445769b (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#15 0x000000000445f95b (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#16 0x0000000004455b6b clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#17 0x000000000445b39c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x445b39c)
#18 0x00000000043dd5fd clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43dd5fd)
#19 0x0000000003fe23ac clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr(clang::Expr const*, llvm::BasicBlock*, llvm::BasicBlock*, unsigned long, clang::Stmt::Likelihood, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3fe23ac)
#20 0x0000000004438c09 (anonymous namespace)::ComplexExprEmitter::VisitAbstractConditionalOperator(clang::AbstractConditionalOperator const*) CGExprComplex.cpp:0:0
#21 0x000000000443925a (anonymous namespace)::ComplexExprEmitter::Visit(clang::Expr*) CGExprComplex.cpp:0:0
#22 0x000000000443973b (anonymous namespace)::ComplexExprEmitter::Visit(clang::Expr*) CGExprComplex.cpp:0:0
#23 0x000000000443d0a8 clang::CodeGen::CodeGenFunction::EmitComplexExprIntoLValue(clang::Expr const*, clang::CodeGen::LValue, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x443d0a8)
#24 0x0000000003f65528 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f65528)
#25 0x0000000003f6d516 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f6d516)
#26 0x0000000003f74ef4 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f74ef4)
#27 0x0000000003fde3a4 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3fde3a4)
#28 0x0000000003ff0fb8 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ff0fb8)
#29 0x000000000405871a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x405871a)
#30 0x0000000004053995 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4053995)
#31 0x0000000004053d7b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4053d7b)
#32 0x000000000405e553 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#33 0x0000000004589ac6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#34 0x000000000457a7c8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457a7c8)
#35 0x00000000065416e4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65416e4)
#36 0x0000000004587678 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4587678)
#37 0x0000000004842f09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4842f09)
#38 0x00000000047c2b9e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47c2b9e)
#39 0x000000000492df6e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x492df6e)
#40 0x0000000000cb235f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcb235f)
#41 0x0000000000ca9dfa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#42 0x00000000045cb0d9 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
#43 0x0000000003b50514 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b50514)
#44 0x00000000045cb6cf 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
#45 0x000000000459115d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x459115d)
#46 0x000000000459224d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x459224d)
#47 0x0000000004599605 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4599605)
#48 0x0000000000caf1a3 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcaf1a3)
#49 0x0000000000b82fe4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb82fe4)
#50 0x00007a4613629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#51 0x00007a4613629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#52 0x0000000000ca98a5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xca98a5)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134