llvm / llvm-project

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

Compiler crash when using float register annotation in conjunction with ASM blocks on Aarch64 #90123

Open calebh opened 6 months ago

calebh commented 6 months ago

I am experiencing a compiler crash when forcing a float variable to live within a certain register, then using that register in some ASM blocks. So far this issue has only cropped up for the Aarch64 project and has not affected my compilation for x64.

Here is an ultra-minimal program that leads to a reproduction:

#include <stdint.h>

void myfun() {
    // Constraining a float to live in an arbitrary floating point register
    // (in this case v22), then using inline assembly causes a crash
    register float v22 asm("v22");
    asm ("" : "=r"(v22) : : );
    asm ("" : : "r"(v22) :);

    // Using a non-floating point register seems to be completely okay
    // These lines do not cause a crash
    register uint64_t x16 asm("x16");
    asm ("" : "=r"(x16) : : );
    asm ("" : : "r"(x16) :);
}

When using the GCC ARM cross compiler this code compiles just fine, which further supports that this is a clang bug.

Here is the command that I'm running to compile:

clang-19 -target aarch64-linux-gnu -c patch.c -o patch.o

The following is outputted to the console:

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: clang-19 -target aarch64-linux-gnu -c patch.c -o patch.o
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module 'patch.c'.
4.  Running pass 'InstructionSelect' on function '@myfun'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM.so.19.0      0x000075ddf482711a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 58
1  libLLVM.so.19.0      0x000075ddf4824d24 llvm::sys::RunSignalHandlers() + 84
2  libLLVM.so.19.0      0x000075ddf476ea34
3  libc.so.6            0x000075ddf3242990
4  libLLVM.so.19.0      0x000075ddf5281506 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) + 86
5  libLLVM.so.19.0      0x000075ddf5222c97 llvm::InstructionSelect::runOnMachineFunction(llvm::MachineFunction&) + 1495
6  libLLVM.so.19.0      0x000075ddf4c0fad7 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 823
7  libLLVM.so.19.0      0x000075ddf497d932 llvm::FPPassManager::runOnFunction(llvm::Function&) + 722
8  libLLVM.so.19.0      0x000075ddf4983453 llvm::FPPassManager::runOnModule(llvm::Module&) + 51
9  libLLVM.so.19.0      0x000075ddf497e084 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1124
10 libclang-cpp.so.19.0 0x000075ddfd0d0a14 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*) + 4852
11 libclang-cpp.so.19.0 0x000075ddfd470639 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1609
12 libclang-cpp.so.19.0 0x000075ddfbfe0b09 clang::ParseAST(clang::Sema&, bool, bool) + 649
13 libclang-cpp.so.19.0 0x000075ddfdf19839 clang::FrontendAction::Execute() + 89
14 libclang-cpp.so.19.0 0x000075ddfde8e914 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 996
15 libclang-cpp.so.19.0 0x000075ddfdf94aee clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 702
16 clang-19             0x00005d5d064f17f1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 3873
17 clang-19             0x00005d5d064eeff5
18 libclang-cpp.so.19.0 0x000075ddfdb2ec3d
19 libLLVM.so.19.0      0x000075ddf476e7d0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 144
20 libclang-cpp.so.19.0 0x000075ddfdb2e561 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 369
21 libclang-cpp.so.19.0 0x000075ddfdaf4935 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 901
22 libclang-cpp.so.19.0 0x000075ddfdaf4b8e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 142
23 libclang-cpp.so.19.0 0x000075ddfdb116fc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 348
24 clang-19             0x00005d5d064eea5e clang_main(int, char**, llvm::ToolContext const&) + 6670
25 clang-19             0x00005d5d064fbbba main + 106
26 libc.so.6            0x000075ddf3228150
27 libc.so.6            0x000075ddf3228209 __libc_start_main + 137
28 clang-19             0x00005d5d064eccc5 _start + 37
clang-19: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 19.0.0 (++20240422083540+0ff992e5f210-1~exp1~20240422083645.455)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
clang-19: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-19: note: diagnostic msg: /tmp/patch-6b1343.c
clang-19: note: diagnostic msg: /tmp/patch-6b1343.sh
clang-19: note: diagnostic msg: 

********************

I have attached the diagnostic files that were requested by the compiler: patch-6b1343.zip

When running with the -Os flag, we see an additional error message:

clang-19 -target aarch64-linux-gnu -Os -c patch.c -o patch.o
patch.c:8:10: error: scalar-to-vector conversion failed, possible invalid constraint for vector type
    8 |     asm ("" : : "r"(v22) :);
      |          ^
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: clang-19 -target aarch64-linux-gnu -Os -c patch.c -o patch.o
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module 'patch.c'.
4.  Running pass 'AArch64 Instruction Selection' on function '@myfun'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM.so.19.0      0x000071963fa2711a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 58
1  libLLVM.so.19.0      0x000071963fa24d24 llvm::sys::RunSignalHandlers() + 84
2  libLLVM.so.19.0      0x000071963f96ea34
3  libc.so.6            0x000071963e442990
4  libLLVM.so.19.0      0x000071963f932c20 llvm::APInt::trunc(unsigned int) const + 272
5  libLLVM.so.19.0      0x000071964027de3c
6  libLLVM.so.19.0      0x00007196402d64e8 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const + 8568
7  libLLVM.so.19.0      0x00007196400fe6f9
8  libLLVM.so.19.0      0x00007196400fe61d
9  libLLVM.so.19.0      0x00007196400fbfe7
10 libLLVM.so.19.0      0x00007196400c6996
11 libLLVM.so.19.0      0x00007196400a0c5d
12 libLLVM.so.19.0      0x000071964009e162 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) + 1954
13 libLLVM.so.19.0      0x00007196402b95e6 llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 246
14 libLLVM.so.19.0      0x00007196402b8cb2 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 4786
15 libLLVM.so.19.0      0x00007196402b6cbe llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1630
16 libLLVM.so.19.0      0x000071963fe0fad7 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 823
17 libLLVM.so.19.0      0x000071963fb7d932 llvm::FPPassManager::runOnFunction(llvm::Function&) + 722
18 libLLVM.so.19.0      0x000071963fb83453 llvm::FPPassManager::runOnModule(llvm::Module&) + 51
19 libLLVM.so.19.0      0x000071963fb7e084 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1124
20 libclang-cpp.so.19.0 0x00007196482d0a14 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*) + 4852
21 libclang-cpp.so.19.0 0x0000719648670639 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1609
22 libclang-cpp.so.19.0 0x00007196471e0b09 clang::ParseAST(clang::Sema&, bool, bool) + 649
23 libclang-cpp.so.19.0 0x0000719649119839 clang::FrontendAction::Execute() + 89
24 libclang-cpp.so.19.0 0x000071964908e914 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 996
25 libclang-cpp.so.19.0 0x0000719649194aee clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 702
26 clang-19             0x00005d570f6047f1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 3873
27 clang-19             0x00005d570f601ff5
28 libclang-cpp.so.19.0 0x0000719648d2ec3d
29 libLLVM.so.19.0      0x000071963f96e7d0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 144
30 libclang-cpp.so.19.0 0x0000719648d2e561 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 369
31 libclang-cpp.so.19.0 0x0000719648cf4935 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 901
32 libclang-cpp.so.19.0 0x0000719648cf4b8e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 142
33 libclang-cpp.so.19.0 0x0000719648d116fc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 348
34 clang-19             0x00005d570f601a5e clang_main(int, char**, llvm::ToolContext const&) + 6670
35 clang-19             0x00005d570f60ebba main + 106
36 libc.so.6            0x000071963e428150
37 libc.so.6            0x000071963e428209 __libc_start_main + 137
38 clang-19             0x00005d570f5ffcc5 _start + 37
clang-19: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 19.0.0 (++20240422083540+0ff992e5f210-1~exp1~20240422083645.455)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
clang-19: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-19: note: diagnostic msg: /tmp/patch-e9243f.c
clang-19: note: diagnostic msg: /tmp/patch-e9243f.sh
clang-19: note: diagnostic msg: 

patch-e9243f.zip

llvmbot commented 6 months ago

@llvm/issue-subscribers-backend-aarch64

Author: Caleb Helbling (calebh)

I am experiencing a compiler crash when forcing a float variable to live within a certain register, then using that register in some ASM blocks. So far this issue has only cropped up for the Aarch64 project and has not affected my compilation for x64. Here is an ultra-minimal program that leads to a reproduction: ``` #include <stdint.h> void myfun() { // Constraining a float to live in an arbitrary floating point register // (in this case v22), then using inline assembly causes a crash register float v22 asm("v22"); asm ("" : "=r"(v22) : : ); asm ("" : : "r"(v22) :); // Using a non-floating point register seems to be completely okay // These lines do not cause a crash register uint64_t x16 asm("x16"); asm ("" : "=r"(x16) : : ); asm ("" : : "r"(x16) :); } ``` When using the GCC ARM cross compiler this code compiles just fine, which further supports that this is a clang bug. Here is the command that I'm running to compile: ``` clang-19 -target aarch64-linux-gnu -c patch.c -o patch.o ``` The following is outputted to the console: ``` 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: clang-19 -target aarch64-linux-gnu -c patch.c -o patch.o 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module 'patch.c'. 4. Running pass 'InstructionSelect' on function '@myfun' Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 libLLVM.so.19.0 0x000075ddf482711a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 58 1 libLLVM.so.19.0 0x000075ddf4824d24 llvm::sys::RunSignalHandlers() + 84 2 libLLVM.so.19.0 0x000075ddf476ea34 3 libc.so.6 0x000075ddf3242990 4 libLLVM.so.19.0 0x000075ddf5281506 llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) + 86 5 libLLVM.so.19.0 0x000075ddf5222c97 llvm::InstructionSelect::runOnMachineFunction(llvm::MachineFunction&) + 1495 6 libLLVM.so.19.0 0x000075ddf4c0fad7 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 823 7 libLLVM.so.19.0 0x000075ddf497d932 llvm::FPPassManager::runOnFunction(llvm::Function&) + 722 8 libLLVM.so.19.0 0x000075ddf4983453 llvm::FPPassManager::runOnModule(llvm::Module&) + 51 9 libLLVM.so.19.0 0x000075ddf497e084 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1124 10 libclang-cpp.so.19.0 0x000075ddfd0d0a14 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*) + 4852 11 libclang-cpp.so.19.0 0x000075ddfd470639 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1609 12 libclang-cpp.so.19.0 0x000075ddfbfe0b09 clang::ParseAST(clang::Sema&, bool, bool) + 649 13 libclang-cpp.so.19.0 0x000075ddfdf19839 clang::FrontendAction::Execute() + 89 14 libclang-cpp.so.19.0 0x000075ddfde8e914 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 996 15 libclang-cpp.so.19.0 0x000075ddfdf94aee clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 702 16 clang-19 0x00005d5d064f17f1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 3873 17 clang-19 0x00005d5d064eeff5 18 libclang-cpp.so.19.0 0x000075ddfdb2ec3d 19 libLLVM.so.19.0 0x000075ddf476e7d0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 144 20 libclang-cpp.so.19.0 0x000075ddfdb2e561 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 369 21 libclang-cpp.so.19.0 0x000075ddfdaf4935 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 901 22 libclang-cpp.so.19.0 0x000075ddfdaf4b8e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 142 23 libclang-cpp.so.19.0 0x000075ddfdb116fc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 348 24 clang-19 0x00005d5d064eea5e clang_main(int, char**, llvm::ToolContext const&) + 6670 25 clang-19 0x00005d5d064fbbba main + 106 26 libc.so.6 0x000075ddf3228150 27 libc.so.6 0x000075ddf3228209 __libc_start_main + 137 28 clang-19 0x00005d5d064eccc5 _start + 37 clang-19: error: clang frontend command failed with exit code 139 (use -v to see invocation) Ubuntu clang version 19.0.0 (++20240422083540+0ff992e5f210-1~exp1~20240422083645.455) Target: aarch64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/lib/llvm-19/bin clang-19: note: diagnostic msg: ******************** PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-19: note: diagnostic msg: /tmp/patch-6b1343.c clang-19: note: diagnostic msg: /tmp/patch-6b1343.sh clang-19: note: diagnostic msg: ******************** ``` I have attached the diagnostic files that were requested by the compiler: [patch-6b1343.zip](https://github.com/llvm/llvm-project/files/15121957/patch-6b1343.zip) When running with the `-Os` flag, we see an additional error message: ``` clang-19 -target aarch64-linux-gnu -Os -c patch.c -o patch.o ``` ``` patch.c:8:10: error: scalar-to-vector conversion failed, possible invalid constraint for vector type 8 | asm ("" : : "r"(v22) :); | ^ 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: clang-19 -target aarch64-linux-gnu -Os -c patch.c -o patch.o 1. <eof> parser at end of file 2. Code generation 3. Running pass 'Function Pass Manager' on module 'patch.c'. 4. Running pass 'AArch64 Instruction Selection' on function '@myfun' Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it): 0 libLLVM.so.19.0 0x000071963fa2711a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 58 1 libLLVM.so.19.0 0x000071963fa24d24 llvm::sys::RunSignalHandlers() + 84 2 libLLVM.so.19.0 0x000071963f96ea34 3 libc.so.6 0x000071963e442990 4 libLLVM.so.19.0 0x000071963f932c20 llvm::APInt::trunc(unsigned int) const + 272 5 libLLVM.so.19.0 0x000071964027de3c 6 libLLVM.so.19.0 0x00007196402d64e8 llvm::TargetLowering::SimplifyDemandedBits(llvm::SDValue, llvm::APInt const&, llvm::APInt const&, llvm::KnownBits&, llvm::TargetLowering::TargetLoweringOpt&, unsigned int, bool) const + 8568 7 libLLVM.so.19.0 0x00007196400fe6f9 8 libLLVM.so.19.0 0x00007196400fe61d 9 libLLVM.so.19.0 0x00007196400fbfe7 10 libLLVM.so.19.0 0x00007196400c6996 11 libLLVM.so.19.0 0x00007196400a0c5d 12 libLLVM.so.19.0 0x000071964009e162 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) + 1954 13 libLLVM.so.19.0 0x00007196402b95e6 llvm::SelectionDAGISel::CodeGenAndEmitDAG() + 246 14 libLLVM.so.19.0 0x00007196402b8cb2 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) + 4786 15 libLLVM.so.19.0 0x00007196402b6cbe llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) + 1630 16 libLLVM.so.19.0 0x000071963fe0fad7 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 823 17 libLLVM.so.19.0 0x000071963fb7d932 llvm::FPPassManager::runOnFunction(llvm::Function&) + 722 18 libLLVM.so.19.0 0x000071963fb83453 llvm::FPPassManager::runOnModule(llvm::Module&) + 51 19 libLLVM.so.19.0 0x000071963fb7e084 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1124 20 libclang-cpp.so.19.0 0x00007196482d0a14 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*) + 4852 21 libclang-cpp.so.19.0 0x0000719648670639 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1609 22 libclang-cpp.so.19.0 0x00007196471e0b09 clang::ParseAST(clang::Sema&, bool, bool) + 649 23 libclang-cpp.so.19.0 0x0000719649119839 clang::FrontendAction::Execute() + 89 24 libclang-cpp.so.19.0 0x000071964908e914 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 996 25 libclang-cpp.so.19.0 0x0000719649194aee clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 702 26 clang-19 0x00005d570f6047f1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 3873 27 clang-19 0x00005d570f601ff5 28 libclang-cpp.so.19.0 0x0000719648d2ec3d 29 libLLVM.so.19.0 0x000071963f96e7d0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 144 30 libclang-cpp.so.19.0 0x0000719648d2e561 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 369 31 libclang-cpp.so.19.0 0x0000719648cf4935 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 901 32 libclang-cpp.so.19.0 0x0000719648cf4b8e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 142 33 libclang-cpp.so.19.0 0x0000719648d116fc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 348 34 clang-19 0x00005d570f601a5e clang_main(int, char**, llvm::ToolContext const&) + 6670 35 clang-19 0x00005d570f60ebba main + 106 36 libc.so.6 0x000071963e428150 37 libc.so.6 0x000071963e428209 __libc_start_main + 137 38 clang-19 0x00005d570f5ffcc5 _start + 37 clang-19: error: clang frontend command failed with exit code 139 (use -v to see invocation) Ubuntu clang version 19.0.0 (++20240422083540+0ff992e5f210-1~exp1~20240422083645.455) Target: aarch64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/lib/llvm-19/bin clang-19: note: diagnostic msg: ******************** PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-19: note: diagnostic msg: /tmp/patch-e9243f.c clang-19: note: diagnostic msg: /tmp/patch-e9243f.sh clang-19: note: diagnostic msg: ``` [patch-e9243f.zip](https://github.com/llvm/llvm-project/files/15122002/patch-e9243f.zip)
v01dXYZ commented 6 months ago

Hi,

When disabling GlobalISel with -mllvm --aarch64-enable-global-isel-at-O=-1, the error you get with -Os can be seen too.

With godbolt, we can also see that:

v01dXYZ commented 6 months ago

Two points:

v01dXYZ commented 6 months ago

we narrow to the following code,


void myfun() {
    // Constraining a float to live in an arbitrary floating point register
    // (in this case v22), then using inline assembly causes a crash
    register float v22 asm("v22");
    asm ("" : "=r"(v22) : : );                           // <---------------- LINE A
    asm ("" : : "r"(v22) :);                             // <---------------- LINE B
}

When commenting out either Line A or Line B, we get with GlobalISel disabled:

Doing the same with GlobalISel enabled,

v01dXYZ commented 6 months ago

@calebh Just to be clear, did you use the asm directive without any ops, did you get the same result with an assembly instruction ?

calebh commented 6 months ago

@calebh Just to be clear, did you use the asm directive without any ops, did you get the same result with an assembly instruction ?

For my application we actually use empty assembly blocks. The asm statements are merely used to trick the compiler into thinking that the v22 variable is live after LINE A, and LINE B is inserted just before the return statement to ensure that the variable lives through the body of the function.

The scenario we're using this trick for is for a micropatch compiler (see https://github.com/purseclab/Patcherex2/issues/24). The register and asm blocks are used to gain control over additional registers not covered by the calling convention. The overall goal is to allow the programmer to write micropatches in C-like syntax, for example a x64 micropatch can be written like this:

if (rcx >= r8) {
    rdi = rsi * rdx; 
}

We then extract the compiled function and insert it into the binary we are patching.

Thanks for pointing out that subregisters (b, h, s, d, q) for the v registers exist. I think I can work around this bug for my application by using those.