[LLVM] error in backend: Broken function found, compilation aborted
The following code reports an error:
union a {
short b;
} __attribute__((transparent_union)) c(union a d) {
return d;
}
int main()
{
return 0;
}
Attribute 'signext' applied to incompatible type!
ptr @c
fatal error: error in backend: Broken module found, compilation aborted!
PLEASE submit a bug report to https://github.com/widberg/llvm-project-widberg-extensions/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-widberg-main/bin/clang -gdwarf-4 -g -o /app/output.s -fno-verbose-asm -c --gcc-toolchain=/opt/compiler-explorer/gcc-11.2.0 -fcolor-diagnostics -fno-crash-diagnostics -mllvm -print-after-all <source>
1. <eof> parser at end of file
2. Optimizer
#0 0x0000000001eba878 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x1eba878)
#1 0x0000000001eb855c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x1eb855c)
#2 0x0000000001e069a6 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x1e069a6)
#3 0x0000000001eaf81e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x1eaf81e)
#4 0x0000000000b3b8ca LLVMErrorHandler(void*, char const*, bool) cc1_main.cpp:0:0
#5 0x0000000001e0f273 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x1e0f273)
#6 0x0000000001e0f3d8 (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x1e0f3d8)
#7 0x00000000019f0d63 (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x19f0d63)
#8 0x00000000021111de llvm::detail::PassModel<llvm::Module, llvm::VerifierPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x21111de)
#9 0x00000000019c1c4c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x19c1c4c)
#10 0x00000000021219a2 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(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>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#11 0x0000000002124c5c (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#12 0x0000000002125291 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*) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x2125291)
#13 0x000000000273792c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x273792c)
#14 0x0000000004450669 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x4450669)
#15 0x0000000002736cc8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x2736cc8)
#16 0x00000000029a5f69 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x29a5f69)
#17 0x00000000029255be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x29255be)
#18 0x0000000002a8570e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x2a8570e)
#19 0x0000000000b3d9c6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0xb3d9c6)
#20 0x0000000000b3548a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#21 0x0000000002778349 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
#22 0x0000000001e068e4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x1e068e4)
#23 0x000000000277893f 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
#24 0x00000000027405a5 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x27405a5)
#25 0x000000000274100d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x274100d)
#26 0x0000000002748f45 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0x2748f45)
#27 0x0000000000b3af3c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-widberg-main/bin/clang+0xb3af3c)
#28 0x0000000000a88374 main (/opt/compiler-explorer/clang-widberg-main/bin/clang+0xa88374)
#29 0x0000701af6429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#30 0x0000701af6429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#31 0x0000000000b34f6e _start (/opt/compiler-explorer/clang-widberg-main/bin/clang+0xb34f6e)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
The bug is only reproducible for widberg fork, and can't be reproduced for LLVM trunk (https://github.com/llvm/llvm-project/commit/ec056f54589d937ae3f74d795b94de886cbb7ec7) (https://godbolt.org/z/P9qf3oYjW).
Originally posted by @zhangqingqing24630 in llvm#127002
Thanks for the report. Sorry this got reported upstream first, I try my best to make all the error messages and README point people to report stuff here but there's only so much I can do.
@zhangqingqing24630 this is the first I've seen someone try to use __attribute__((transparent_union)) with my compiler, I definitely don't have it implemented yet. I won't add that any time soon so you're best off avoiding that attribute for now.
@zhangqingqing24630 Rebasing onto the latest llvm-project/main seems to have fixed this with no further changes on my part https://godbolt.org/z/P9qf3oYjW, https://godbolt.org/z/Mcar1cajc. It even works with my __usercall calling convention https://godbolt.org/z/Krs543h5r. There's a new release based on llvm-project/llvmorg-21.1.0 and a new nightly build based on llvm-project/main. I'm not sure what was causing the problem before, but if it comes up again, please reopen this issue.