llvm / llvm-project

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

aarch64: Invalid register name passed to __arm_rsr64 causes an ICE #104614

Open pinskia opened 3 months ago

pinskia commented 3 months ago

Take:

#include <arm_acle.h>
void f()
{
        __arm_rsr64 ("iadr_el1"); // incorrect spelling
        __arm_rsr64 ("aidr_el1"); // correct spelling
}

This causes an internal compiler error instead of a friendly error message:

fatal error: error in backend: Invalid register name "iadr_el1".
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/bin/clang++ -gdwarf-4 -g -o /app/output.s -fverbose-asm -S -target aarch64-linux-gnu --gcc-toolchain=/opt/compiler-explorer/arm64/gcc-12.2.0/aarch64-unknown-linux-gnu --sysroot=/opt/compiler-explorer/arm64/gcc-12.2.0/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot -fcolor-diagnostics -fno-crash-diagnostics -xc -O3 -fno-unroll-loops -fno-verbose-asm -g0 -march=armv9-a <source>
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module '<source>'.
4.  Running pass 'AArch64 Instruction Selection' on function '@f'
 #0 0x000000000384b7d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x384b7d8)
 #1 0x0000000003849944 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3849944)
 #2 0x0000000003794553 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3794553)
 #3 0x000000000384111e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x384111e)
 #4 0x0000000000c9dac6 (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc9dac6)
 #5 0x000000000379e5b3 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x379e5b3)
 #6 0x0000000000e534af llvm::AArch64TargetLowering::getRegisterByName(char const*, llvm::LLT, llvm::MachineFunction const&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0xe534af)
 #7 0x0000000004a38275 llvm::SelectionDAGISel::Select_READ_REGISTER(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a38275)
 #8 0x0000000004a3deb2 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a3deb2)
 #9 0x0000000000e237ed (anonymous namespace)::AArch64DAGToDAGISel::Select(llvm::SDNode*) AArch64ISelDAGToDAG.cpp:0:0
#10 0x0000000004a36e44 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a36e44)
#11 0x0000000004a460b1 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a460b1)
#12 0x0000000004a48a95 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a48a95)
#13 0x0000000004a4a580 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a4a580)
#14 0x0000000004a369d1 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a369d1)
#15 0x0000000002c9326b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#16 0x00000000031deb72 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x31deb72)
#17 0x00000000031dee31 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x31dee31)
#18 0x00000000031de0cb llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x31de0cb)
#19 0x0000000003ae3f56 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-trunk/bin/clang+++0x3ae3f56)
#20 0x0000000004121c3c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4121c3c)
#21 0x00000000060cf04c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x60cf04c)
#22 0x00000000041223d5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x41223d5)
#23 0x00000000043c8be1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x43c8be1)
#24 0x000000000434bb4b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x434bb4b)
#25 0x00000000044b01e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44b01e3)
#26 0x0000000000c9fa0c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc9fa0c)
#27 0x0000000000c9994d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x000000000416b899 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
#29 0x0000000003794453 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3794453)
#30 0x000000000416bab9 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
#31 0x0000000004131457 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4131457)
#32 0x0000000004131e0d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4131e0d)
#33 0x000000000413b8ec clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x413b8ec)
#34 0x0000000000c9ccf1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc9ccf1)
#35 0x0000000000b72924 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xb72924)
#36 0x00007521d6a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#37 0x00007521d6a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#38 0x0000000000c993ee _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc993ee)
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
Compiler returned: 70
llvmbot commented 3 months ago

@llvm/issue-subscribers-backend-aarch64

Author: Andrew Pinski (pinskia)

Take: ``` #include <arm_acle.h> void f() { __arm_rsr64 ("iadr_el1"); // incorrect spelling __arm_rsr64 ("aidr_el1"); // correct spelling } ``` This causes an internal compiler error instead of a friendly error message: ``` fatal error: error in backend: Invalid register name "iadr_el1". 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/bin/clang++ -gdwarf-4 -g -o /app/output.s -fverbose-asm -S -target aarch64-linux-gnu --gcc-toolchain=/opt/compiler-explorer/arm64/gcc-12.2.0/aarch64-unknown-linux-gnu --sysroot=/opt/compiler-explorer/arm64/gcc-12.2.0/aarch64-unknown-linux-gnu/aarch64-unknown-linux-gnu/sysroot -fcolor-diagnostics -fno-crash-diagnostics -xc -O3 -fno-unroll-loops -fno-verbose-asm -g0 -march=armv9-a <source> 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module '<source>'. 4. Running pass 'AArch64 Instruction Selection' on function '@f' #0 0x000000000384b7d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x384b7d8) #1 0x0000000003849944 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3849944) #2 0x0000000003794553 llvm::CrashRecoveryContext::HandleExit(int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3794553) #3 0x000000000384111e llvm::sys::Process::Exit(int, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x384111e) #4 0x0000000000c9dac6 (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc9dac6) #5 0x000000000379e5b3 llvm::report_fatal_error(llvm::Twine const&, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x379e5b3) #6 0x0000000000e534af llvm::AArch64TargetLowering::getRegisterByName(char const*, llvm::LLT, llvm::MachineFunction const&) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0xe534af) #7 0x0000000004a38275 llvm::SelectionDAGISel::Select_READ_REGISTER(llvm::SDNode*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a38275) #8 0x0000000004a3deb2 llvm::SelectionDAGISel::SelectCodeCommon(llvm::SDNode*, unsigned char const*, unsigned int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a3deb2) #9 0x0000000000e237ed (anonymous namespace)::AArch64DAGToDAGISel::Select(llvm::SDNode*) AArch64ISelDAGToDAG.cpp:0:0 #10 0x0000000004a36e44 llvm::SelectionDAGISel::DoInstructionSelection() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a36e44) #11 0x0000000004a460b1 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a460b1) #12 0x0000000004a48a95 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a48a95) #13 0x0000000004a4a580 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a4a580) #14 0x0000000004a369d1 llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a369d1) #15 0x0000000002c9326b llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0 #16 0x00000000031deb72 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x31deb72) #17 0x00000000031dee31 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x31dee31) #18 0x00000000031de0cb llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x31de0cb) #19 0x0000000003ae3f56 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-trunk/bin/clang+++0x3ae3f56) #20 0x0000000004121c3c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4121c3c) #21 0x00000000060cf04c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x60cf04c) #22 0x00000000041223d5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x41223d5) #23 0x00000000043c8be1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x43c8be1) #24 0x000000000434bb4b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x434bb4b) #25 0x00000000044b01e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x44b01e3) #26 0x0000000000c9fa0c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc9fa0c) #27 0x0000000000c9994d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #28 0x000000000416b899 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 #29 0x0000000003794453 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3794453) #30 0x000000000416bab9 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 #31 0x0000000004131457 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4131457) #32 0x0000000004131e0d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4131e0d) #33 0x000000000413b8ec clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x413b8ec) #34 0x0000000000c9ccf1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc9ccf1) #35 0x0000000000b72924 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xb72924) #36 0x00007521d6a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #37 0x00007521d6a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #38 0x0000000000c993ee _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xc993ee) clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation) Compiler returned: 70 ```
v01dXYZ commented 3 months ago

The code responsible:

https://github.com/llvm/llvm-project/blob/8b1916b7666ae29c3ca2a196f5d1062e2d51f10f/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp#L11344

It seems an easy task to add an error message for LLVM/Clang. I would gladly take a look at it.

v01dXYZ commented 3 months ago

We could add some name lookup to BuiltinARMSpecialReg (clang) which only supports a colon separated register number (base 8). There is in LLVM SystemOperands.td but I don't know how to use it with clang.