llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.04k stars 11.58k forks source link

Clang crashes when compiling a variadic function while targeting mips3 #98716

Open imaandrew opened 2 months ago

imaandrew commented 2 months ago

When compiling any variadic function with options -target mips-linux-gnu -march=mips3, clang will crash and produce the following backtrace:

clang-19: /home/andrew/llvm-project/llvm/lib/Target/Mips/MipsSEInstrInfo.cpp:172: virtual void llvm::MipsSEInstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineBasicBlock::iterator, const llvm::DebugLoc&, llvm::MCRegister, llvm::MCRegister, bool) const: Assertion `Opc && "Cannot copy registers"' 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: /home/andrew/llvm-project/build/bin/clang-19 -cc1 -triple mips-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name test.c -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu mips3 -target-feature -noabicalls -target-feature +fpxx -target-feature +nooddspreg -target-abi o32 -mfloat-abi hard -debugger-tuning=gdb -fdebug-compilation-dir=/home/andrew/llvm-project/build/bin -fcoverage-compilation-dir=/home/andrew/llvm-project/build/bin -resource-dir /home/andrew/llvm-project/build/lib/clang/19 -internal-isystem /home/andrew/llvm-project/build/lib/clang/19/include -internal-isystem /usr/local/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -o /tmp/test-c2a4ba.o -x c test.c
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'test.c'.
4.      Running pass 'Post-RA pseudo instruction expansion pass' on function '@func'
 #0 0x000055ebe942b4f0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/andrew/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x000055ebe942b903 PrintStackTraceSignalHandler(void*) /home/andrew/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x000055ebe9428db7 llvm::sys::RunSignalHandlers() /home/andrew/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x000055ebe942adcd SignalHandler(int) /home/andrew/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007fb2f06aaae0 (/usr/lib/libc.so.6+0x3cae0)
 #5 0x00007fb2f0702e44 (/usr/lib/libc.so.6+0x94e44)
 #6 0x00007fb2f06aaa30 raise (/usr/lib/libc.so.6+0x3ca30)
 #7 0x00007fb2f06924c3 abort (/usr/lib/libc.so.6+0x244c3)
 #8 0x00007fb2f06923df (/usr/lib/libc.so.6+0x243df)
 #9 0x00007fb2f06a2c67 (/usr/lib/libc.so.6+0x34c67)
#10 0x000055ebe7960a36 llvm::MipsSEInstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::DebugLoc const&, llvm::MCRegister, llvm::MCRegister, bool) const /home/andrew/llvm-project/llvm/lib/Target/Mips/MipsSEInstrInfo.cpp:174:36
#11 0x000055ebe831d21d llvm::TargetInstrInfo::lowerCopy(llvm::MachineInstr*, llvm::TargetRegisterInfo const*) const /home/andrew/llvm-project/llvm/lib/CodeGen/TargetInstrInfo.cpp:825:14
#12 0x000055ebe857ab57 (anonymous namespace)::ExpandPostRA::runOnMachineFunction(llvm::MachineFunction&) /home/andrew/llvm-project/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp:149:20
#13 0x000055ebe8150408 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/andrew/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:94:33
#14 0x000055ebe8bced2d llvm::FPPassManager::runOnFunction(llvm::Function&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1442:20
#15 0x000055ebe8bceffe llvm::FPPassManager::runOnModule(llvm::Module&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1488:13
#16 0x000055ebe8bcf44a (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1557:20
#17 0x000055ebe8bca025 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:542:13
#18 0x000055ebe8bcfd1d llvm::legacy::PassManager::run(llvm::Module&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1685:1
#19 0x000055ebea30ef57 (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) /home/andrew/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1158:3
#20 0x000055ebea30f167 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /home/andrew/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1182:7
#21 0x000055ebea3102c6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /home/andrew/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1341:25
#22 0x000055ebea457b95 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/andrew/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:354:20
#23 0x000055ebedcd77ca clang::ParseAST(clang::Sema&, bool, bool) /home/andrew/llvm-project/clang/lib/Parse/ParseAST.cpp:183:14
#24 0x000055ebea9df846 clang::ASTFrontendAction::ExecuteAction() /home/andrew/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1192:11
#25 0x000055ebea45bfc4 clang::CodeGenAction::ExecuteAction() /home/andrew/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1145:5
#26 0x000055ebea9df140 clang::FrontendAction::Execute() /home/andrew/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1082:38
#27 0x000055ebea8f11e0 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/andrew/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1061:42
#28 0x000055ebeab9a188 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/andrew/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:280:38
#29 0x000055ebe78ff652 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/andrew/llvm-project/clang/tools/driver/cc1_main.cpp:283:40
#30 0x000055ebe78f0c6f ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/andrew/llvm-project/clang/tools/driver/driver.cpp:215:20
#31 0x000055ebe78f11a7 clang_main(int, char**, llvm::ToolContext const&) /home/andrew/llvm-project/clang/tools/driver/driver.cpp:256:26
#32 0x000055ebe792b05a main /home/andrew/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:20
#33 0x00007fb2f0693c88 (/usr/lib/libc.so.6+0x25c88)
#34 0x00007fb2f0693d4c __libc_start_main (/usr/lib/libc.so.6+0x25d4c)
#35 0x000055ebe78f0025 _start (/home/andrew/llvm-project/build/bin/clang-19+0x78f7025)
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 19.0.0git (git@github.com:llvm/llvm-project.git 594989918bf9e178f3b7c5e200d700d0574f15ec)
Target: mips-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/andrew/llvm-project/build/bin
Build config: +unoptimized, +assertions

Example file:

void func(const char* x, ...) {}

This crash does not happen when using the n32/n64 ABIs, only the default o32 ABI

llvmbot commented 2 months ago

@llvm/issue-subscribers-backend-mips

Author: Andrew (imaandrew)

When compiling any variadic function with options `-target mips-linux-gnu -march=mips3`, clang will crash and produce the following backtrace: ``` clang-19: /home/andrew/llvm-project/llvm/lib/Target/Mips/MipsSEInstrInfo.cpp:172: virtual void llvm::MipsSEInstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineBasicBlock::iterator, const llvm::DebugLoc&, llvm::MCRegister, llvm::MCRegister, bool) const: Assertion `Opc && "Cannot copy registers"' 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: /home/andrew/llvm-project/build/bin/clang-19 -cc1 -triple mips-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name test.c -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu mips3 -target-feature -noabicalls -target-feature +fpxx -target-feature +nooddspreg -target-abi o32 -mfloat-abi hard -debugger-tuning=gdb -fdebug-compilation-dir=/home/andrew/llvm-project/build/bin -fcoverage-compilation-dir=/home/andrew/llvm-project/build/bin -resource-dir /home/andrew/llvm-project/build/lib/clang/19 -internal-isystem /home/andrew/llvm-project/build/lib/clang/19/include -internal-isystem /usr/local/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -o /tmp/test-c2a4ba.o -x c test.c 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module 'test.c'. 4. Running pass 'Post-RA pseudo instruction expansion pass' on function '@func' #0 0x000055ebe942b4f0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/andrew/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22 #1 0x000055ebe942b903 PrintStackTraceSignalHandler(void*) /home/andrew/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1 #2 0x000055ebe9428db7 llvm::sys::RunSignalHandlers() /home/andrew/llvm-project/llvm/lib/Support/Signals.cpp:105:20 #3 0x000055ebe942adcd SignalHandler(int) /home/andrew/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1 #4 0x00007fb2f06aaae0 (/usr/lib/libc.so.6+0x3cae0) #5 0x00007fb2f0702e44 (/usr/lib/libc.so.6+0x94e44) #6 0x00007fb2f06aaa30 raise (/usr/lib/libc.so.6+0x3ca30) #7 0x00007fb2f06924c3 abort (/usr/lib/libc.so.6+0x244c3) #8 0x00007fb2f06923df (/usr/lib/libc.so.6+0x243df) #9 0x00007fb2f06a2c67 (/usr/lib/libc.so.6+0x34c67) #10 0x000055ebe7960a36 llvm::MipsSEInstrInfo::copyPhysReg(llvm::MachineBasicBlock&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::DebugLoc const&, llvm::MCRegister, llvm::MCRegister, bool) const /home/andrew/llvm-project/llvm/lib/Target/Mips/MipsSEInstrInfo.cpp:174:36 #11 0x000055ebe831d21d llvm::TargetInstrInfo::lowerCopy(llvm::MachineInstr*, llvm::TargetRegisterInfo const*) const /home/andrew/llvm-project/llvm/lib/CodeGen/TargetInstrInfo.cpp:825:14 #12 0x000055ebe857ab57 (anonymous namespace)::ExpandPostRA::runOnMachineFunction(llvm::MachineFunction&) /home/andrew/llvm-project/llvm/lib/CodeGen/ExpandPostRAPseudos.cpp:149:20 #13 0x000055ebe8150408 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) /home/andrew/llvm-project/llvm/lib/CodeGen/MachineFunctionPass.cpp:94:33 #14 0x000055ebe8bced2d llvm::FPPassManager::runOnFunction(llvm::Function&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1442:20 #15 0x000055ebe8bceffe llvm::FPPassManager::runOnModule(llvm::Module&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1488:13 #16 0x000055ebe8bcf44a (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1557:20 #17 0x000055ebe8bca025 llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:542:13 #18 0x000055ebe8bcfd1d llvm::legacy::PassManager::run(llvm::Module&) /home/andrew/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1685:1 #19 0x000055ebea30ef57 (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) /home/andrew/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1158:3 #20 0x000055ebea30f167 (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /home/andrew/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1182:7 #21 0x000055ebea3102c6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /home/andrew/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1341:25 #22 0x000055ebea457b95 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/andrew/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:354:20 #23 0x000055ebedcd77ca clang::ParseAST(clang::Sema&, bool, bool) /home/andrew/llvm-project/clang/lib/Parse/ParseAST.cpp:183:14 #24 0x000055ebea9df846 clang::ASTFrontendAction::ExecuteAction() /home/andrew/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1192:11 #25 0x000055ebea45bfc4 clang::CodeGenAction::ExecuteAction() /home/andrew/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1145:5 #26 0x000055ebea9df140 clang::FrontendAction::Execute() /home/andrew/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1082:38 #27 0x000055ebea8f11e0 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/andrew/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1061:42 #28 0x000055ebeab9a188 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/andrew/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:280:38 #29 0x000055ebe78ff652 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/andrew/llvm-project/clang/tools/driver/cc1_main.cpp:283:40 #30 0x000055ebe78f0c6f ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /home/andrew/llvm-project/clang/tools/driver/driver.cpp:215:20 #31 0x000055ebe78f11a7 clang_main(int, char**, llvm::ToolContext const&) /home/andrew/llvm-project/clang/tools/driver/driver.cpp:256:26 #32 0x000055ebe792b05a main /home/andrew/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:20 #33 0x00007fb2f0693c88 (/usr/lib/libc.so.6+0x25c88) #34 0x00007fb2f0693d4c __libc_start_main (/usr/lib/libc.so.6+0x25d4c) #35 0x000055ebe78f0025 _start (/home/andrew/llvm-project/build/bin/clang-19+0x78f7025) clang: error: unable to execute command: Aborted clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 19.0.0git (git@github.com:llvm/llvm-project.git 594989918bf9e178f3b7c5e200d700d0574f15ec) Target: mips-unknown-linux-gnu Thread model: posix InstalledDir: /home/andrew/llvm-project/build/bin Build config: +unoptimized, +assertions ``` Example file: ```c void func(const char* x, ...) {} ``` This crash does not happen when using the n32/n64 ABIs, only the default o32 ABI