<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/109778>109778</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang crash assigning to a global named register variable
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DavidSpickett
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/fcMnqKGxM
```
#include <stdint.h>
register uint64_t t asm ("x21");
void fn() {
t = 1;
}
```
Compile with:
```
$ ./bin/clang -target aarch64-linux-gnu /tmp/test.c -c -o /dev/null
```
Crashes:
```
fatal error: error in backend: Invalid register name "x21".
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: ./bin/clang -target aarch64-linux-gnu /tmp/test.c -c -o /dev/null
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module '/tmp/test.c'.
4. Running pass 'AArch64 Instruction Selection' on function '@fn'
#0 0x0000ffffa92c8a14 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMSupport.so.20.0git+0x188a14)
#1 0x0000ffffa92c6884 llvm::sys::RunSignalHandlers() (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMSupport.so.20.0git+0x186884)
#2 0x0000ffffa9200ebc (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) CrashRecoveryContext.cpp:0:0
#3 0x0000ffffa9200e4c llvm::CrashRecoveryContext::HandleExit(int) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMSupport.so.20.0git+0xc0e4c)
#4 0x0000ffffa92c2d44 llvm::sys::Process::Exit(int, bool) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMSupport.so.20.0git+0x182d44)
#5 0x0000aaaab717e87c llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>::~IntrusiveRefCntPtr() (./bin/clang+0x1287c)
#6 0x0000ffffa9213a0c llvm::report_fatal_error(llvm::Twine const&, bool) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMSupport.so.20.0git+0xd3a0c)
#7 0x0000ffffb3a876e8 llvm::AArch64TargetLowering::getRegisterByName(char const*, llvm::LLT, llvm::MachineFunction const&) const (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMAArch64CodeGen.so.20.0git+0x2476e8)
#8 0x0000ffffa881473c llvm::SelectionDAGISel::Select_WRITE_REGISTER(llvm::SDNode*) (/home/david.spickett/build-llvm-aarch64/bin/../lib/../lib/libLLVMSelectionDAG.so.20.0git+0x2a473c)
#9 0x0000ffffb3a21054 (anonymous namespace)::AArch64DAGToDAGISel::Select(llvm::SDNode*) AArch64ISelDAGToDAG.cpp:0:0
#10 0x0000ffffa8810458 llvm::SelectionDAGISel::DoInstructionSelection() (/home/david.spickett/build-llvm-aarch64/bin/../lib/../lib/libLLVMSelectionDAG.so.20.0git+0x2a0458)
#11 0x0000ffffa880f340 llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/home/david.spickett/build-llvm-aarch64/bin/../lib/../lib/libLLVMSelectionDAG.so.20.0git+0x29f340)
#12 0x0000ffffa880d270 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/../lib/libLLVMSelectionDAG.so.20.0git+0x29d270)
#13 0x0000ffffa880a76c llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/../lib/libLLVMSelectionDAG.so.20.0git+0x29a76c)
#14 0x0000ffffa88081dc llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/../lib/libLLVMSelectionDAG.so.20.0git+0x2981dc)
#15 0x0000ffffac95d3f4 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMCodeGen.so.20.0git+0x34d3f4)
#16 0x0000ffffa96c7330 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMCore.so.20.0git+0x297330)
#17 0x0000ffffa96cefe8 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMCore.so.20.0git+0x29efe8)
#18 0x0000ffffa96c7d10 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMCore.so.20.0git+0x297d10)
#19 0x0000ffffad0817d8 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/david.spickett/build-llvm-aarch64/bin/../lib/libclangCodeGen.so.20.0git+0xf17d8)
#20 0x0000ffffad49f740 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libclangCodeGen.so.20.0git+0x50f740)
#21 0x0000ffffa5de9a18 clang::ParseAST(clang::Sema&, bool, bool) (/home/david.spickett/build-llvm-aarch64/bin/../lib/../lib/libclangParse.so.20.0git+0x39a18)
#22 0x0000ffffabaddf08 clang::FrontendAction::Execute() (/home/david.spickett/build-llvm-aarch64/bin/../lib/libclangFrontend.so.20.0git+0x13df08)
#23 0x0000ffffaba5bd44 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libclangFrontend.so.20.0git+0xbbd44)
#24 0x0000ffffaef33cc4 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libclangFrontendTool.so.20.0git+0x3cc4)
#25 0x0000aaaab717e3c4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (./bin/clang+0x123c4)
#26 0x0000aaaab717aee0 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x0000ffffab74d3cc 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::$_0>(long) Job.cpp:0:0
#28 0x0000ffffa9200de0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libLLVMSupport.so.20.0git+0xc0de0)
#29 0x0000ffffab74c600 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/david.spickett/build-llvm-aarch64/bin/../lib/libclangDriver.so.20.0git+0xcc600)
#30 0x0000ffffab710690 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/home/david.spickett/build-llvm-aarch64/bin/../lib/libclangDriver.so.20.0git+0x90690)
#31 0x0000ffffab710878 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/home/david.spickett/build-llvm-aarch64/bin/../lib/libclangDriver.so.20.0git+0x90878)
#32 0x0000ffffab729728 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/david.spickett/build-llvm-aarch64/bin/../lib/libclangDriver.so.20.0git+0xa9728)
#33 0x0000aaaab717a30c clang_main(int, char**, llvm::ToolContext const&) (./bin/clang+0xe30c)
#34 0x0000aaaab7187c44 main (./bin/clang+0x1bc44)
#35 0x0000ffffa8cb73fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#36 0x0000ffffa8cb74cc call_init ./csu/../csu/libc-start.c:128:20
#37 0x0000ffffa8cb74cc __libc_start_main ./csu/../csu/libc-start.c:379:5
#38 0x0000aaaab7178bf0 _start (./bin/clang+0xcbf0)
clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 20.0.0git (https://github.com/llvm/llvm-project.git be0b1142df7733633354ef1f73d0379bcd2ccb54)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/david.spickett/build-llvm-aarch64/bin
Build config: +assertions
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/test-b8124c.c
clang: note: diagnostic msg: /tmp/test-b8124c.sh
clang: note: diagnostic msg:
********************
```
If I remove the assignment, the error does not happen.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWs1y47ayfhp6g7KKBCiRWnhB68fjXE_sspRkqQIBUMIdElAAULbv4j77KYCURFDSOHPieOrUSTkemvj7vu5Gd6MJrDVfC8ZuguFtMJxe4dpspLqZ4h2niy0n35gxV7mkbzcbY7Y6QFkA5wGcryXNZWkGUq0DOP-_AM4L8lX8-T93r1-DcBqEWft7FLY_zZ8QcUHKmjIQoIk2lAsz2ARo1h2j2JprwxSouTCjeGWAAVhXIIBpAOErjAIIAzgO0G131E5yCgrhOo1BkLSNwIAATUF07J1Mz0KbyGrLSwZeuNlYlufhx2AQwHnORQDnpMRiDa4NVmtmAMaKbEbxdclF_Xq9FjUI4NxUW_ubaTMg4JqAa2nfUrYL4FzUZXkeicJ6w_QlEAU2uARMKakClDUPgAuQY_KNCWrf3YsdLjkFB0kKXDFwEN6gmejpYZYtZkDXecUNwCCv10CxrVQGGAl66uZmU-cDIqsAzstyt__neqvk_zJiAjjn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