llvm-project
llvm-project copied to clipboard
[PowerPC] Clang ICE in ConstantFolding.cpp when compiling __builtin_ppc_national2packed on PowerPC
Reproducer: https://godbolt.org/z/hv8nx1fsM
Compile with Clang trunk for PowerPC64LE: --target=powerpc64le-linux-gnu -mcpu=power9. The crash is reproducible with Clang trunk and was first reproducible with Clang 21.1.
vector unsigned char tBcd_National2packed_imm1(vector unsigned char a) {
return __builtin_ppc_national2packed(a, '\1', (int)0);
}
Backtrace:
clang++: /root/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp:183: llvm::Constant* {anonymous}::FoldBitCast(llvm::Constant*, llvm::Type*, const llvm::DataLayout&): Assertion `CastInst::castIsValid(Instruction::BitCast, C, DestTy) && "Invalid constantexpr bitcast!"' 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 --target=powerpc64le-linux-gnu -mcpu=power9 <source>
1. <eof> parser at end of file
2. <source>:1:22: LLVM IR generation of declaration 'tBcd_National2packed_imm1'
3. <source>:1:22: Generating code for declaration 'tBcd_National2packed_imm1'
#0 0x000000000446e988 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x446e988)
#1 0x000000000446b834 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x446b834)
#2 0x000000000446be6c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x446be6c)
#3 0x00000000043aa748 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x000073efccc45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000073efccc9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x000073efccc4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x000073efccc288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000073efccc2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000073efccc3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x000000000325ee3f (anonymous namespace)::FoldBitCast(llvm::Constant*, llvm::Type*, llvm::DataLayout const&) ConstantFolding.cpp:0:0
#11 0x000000000325efc9 llvm::ConstantFoldCastOperand(unsigned int, llvm::Constant*, llvm::Type*, llvm::DataLayout const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x325efc9)
#12 0x0000000004e0ded6 llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::MDNode*, llvm::FMFSource) (.constprop.0) CGBuiltin.cpp:0:0
#13 0x0000000004e2b961 clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(clang::GlobalDecl, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e2b961)
#14 0x00000000049570ce clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49570ce)
#15 0x00000000049c651c (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#16 0x00000000049bba70 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#17 0x00000000049bdcdb (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#18 0x00000000049c20bb (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#19 0x00000000049bba96 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#20 0x00000000049c151c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49c151c)
#21 0x0000000004ae5ded clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ae5ded)
#22 0x0000000004af5e9b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4af5e9b)
#23 0x0000000004b5e996 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b5e996)
#24 0x0000000004b743b4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b743b4)
#25 0x0000000004be4a9a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4be4a9a)
#26 0x0000000004bdde84 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bdde84)
#27 0x0000000004bdebd0 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bdebd0)
#28 0x0000000004bebce1 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#29 0x0000000004f6a059 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#30 0x0000000004f5b0f4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f5b0f4)
#31 0x0000000006d80ed4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d80ed4)
#32 0x0000000004f67ee8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f67ee8)
#33 0x0000000005293618 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5293618)
#34 0x00000000052206fd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52206fd)
#35 0x000000000536838d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x536838d)
#36 0x0000000000daaabc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdaaabc)
#37 0x0000000000da16da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#38 0x0000000000da185d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#39 0x0000000004fe0bb9 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
#40 0x00000000043aab84 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43aab84)
#41 0x0000000004fe1725 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
#42 0x0000000004f993d2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f993d2)
#43 0x0000000004f9dd37 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+++0x4f9dd37)
#44 0x0000000004fa8405 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fa8405)
#45 0x0000000000da6fba clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda6fba)
#46 0x0000000000cc2d0a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc2d0a)
#47 0x000073efccc2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#48 0x000073efccc2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#49 0x0000000000da1085 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda1085)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
This testcase was generated by fuzzer.
@llvm/issue-subscribers-clang-codegen
Author: RainFly (RainFly-code)
Reproducer:
https://godbolt.org/z/hv8nx1fsM
Compile with Clang trunk for PowerPC64LE: --target=powerpc64le-linux-gnu -mcpu=power9. The crash is reproducible with Clang trunk and was first reproducible with Clang 21.1.
vector unsigned char tBcd_National2packed_imm1(vector unsigned char a) {
return __builtin_ppc_national2packed(a, '\1', (int)0);
}
Backtrace:
clang++: /root/llvm-project/llvm/lib/Analysis/ConstantFolding.cpp:183: llvm::Constant* {anonymous}::FoldBitCast(llvm::Constant*, llvm::Type*, const llvm::DataLayout&): Assertion `CastInst::castIsValid(Instruction::BitCast, C, DestTy) && "Invalid constantexpr bitcast!"' 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 --target=powerpc64le-linux-gnu -mcpu=power9 <source>
1. <eof> parser at end of file
2. <source>:1:22: LLVM IR generation of declaration 'tBcd_National2packed_imm1'
3. <source>:1:22: Generating code for declaration 'tBcd_National2packed_imm1'
#<!-- -->0 0x000000000446e988 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x446e988)
#<!-- -->1 0x000000000446b834 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x446b834)
#<!-- -->2 0x000000000446be6c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x446be6c)
#<!-- -->3 0x00000000043aa748 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#<!-- -->4 0x000073efccc45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#<!-- -->5 0x000073efccc9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#<!-- -->6 0x000073efccc4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#<!-- -->7 0x000073efccc288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#<!-- -->8 0x000073efccc2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#<!-- -->9 0x000073efccc3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#<!-- -->10 0x000000000325ee3f (anonymous namespace)::FoldBitCast(llvm::Constant*, llvm::Type*, llvm::DataLayout const&) ConstantFolding.cpp:0:0
#<!-- -->11 0x000000000325efc9 llvm::ConstantFoldCastOperand(unsigned int, llvm::Constant*, llvm::Type*, llvm::DataLayout const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x325efc9)
#<!-- -->12 0x0000000004e0ded6 llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&, llvm::MDNode*, llvm::FMFSource) (.constprop.0) CGBuiltin.cpp:0:0
#<!-- -->13 0x0000000004e2b961 clang::CodeGen::CodeGenFunction::EmitBuiltinExpr(clang::GlobalDecl, unsigned int, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e2b961)
#<!-- -->14 0x00000000049570ce clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49570ce)
#<!-- -->15 0x00000000049c651c (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#<!-- -->16 0x00000000049bba70 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#<!-- -->17 0x00000000049bdcdb (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
#<!-- -->18 0x00000000049c20bb (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#<!-- -->19 0x00000000049bba96 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#<!-- -->20 0x00000000049c151c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49c151c)
#<!-- -->21 0x0000000004ae5ded clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ae5ded)
#<!-- -->22 0x0000000004af5e9b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4af5e9b)
#<!-- -->23 0x0000000004b5e996 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b5e996)
#<!-- -->24 0x0000000004b743b4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b743b4)
#<!-- -->25 0x0000000004be4a9a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4be4a9a)
#<!-- -->26 0x0000000004bdde84 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bdde84)
#<!-- -->27 0x0000000004bdebd0 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bdebd0)
#<!-- -->28 0x0000000004bebce1 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#<!-- -->29 0x0000000004f6a059 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#<!-- -->30 0x0000000004f5b0f4 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f5b0f4)
#<!-- -->31 0x0000000006d80ed4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d80ed4)
#<!-- -->32 0x0000000004f67ee8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f67ee8)
#<!-- -->33 0x0000000005293618 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5293618)
#<!-- -->34 0x00000000052206fd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x52206fd)
#<!-- -->35 0x000000000536838d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x536838d)
#<!-- -->36 0x0000000000daaabc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdaaabc)
#<!-- -->37 0x0000000000da16da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#<!-- -->38 0x0000000000da185d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#<!-- -->39 0x0000000004fe0bb9 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
#<!-- -->40 0x00000000043aab84 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43aab84)
#<!-- -->41 0x0000000004fe1725 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
#<!-- -->42 0x0000000004f993d2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f993d2)
#<!-- -->43 0x0000000004f9dd37 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+++0x4f9dd37)
#<!-- -->44 0x0000000004fa8405 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fa8405)
#<!-- -->45 0x0000000000da6fba clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda6fba)
#<!-- -->46 0x0000000000cc2d0a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc2d0a)
#<!-- -->47 0x000073efccc2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#<!-- -->48 0x000073efccc2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#<!-- -->49 0x0000000000da1085 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda1085)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
This testcase was generated by fuzzer.
i would like to work on it