Skip to content

clang crashes when compiling aarch64 inline assembly with optimization enabled #153442

@csh-lovenico

Description

@csh-lovenico

Environment

Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

operating system: ubuntu 24.04
clang is installed using apt.

Minimal Reproduction Sample

// armtest.c
int main(void) {
  	register float a0 asm("v0");

  	for (int i = 0; i < 2; ++i) {
  		__asm__ volatile("nop" : [a0] "+w"(a0)::);
  	}

  	return 0;
}

compiling command:

clang --target=aarch64-linux-gnu armtest.c -O1

for comparison, gcc works well:

aarch64-linux-gnu-gcc armtest.c -O1

Output

armtest.c:9:22: error: scalar-to-vector conversion failed, possible invalid constraint for vector type
    9 |                 __asm__ volatile("nop" : [a0] "+w"(a0)::);
      |                                  ^
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: /usr/lib/llvm-18/bin/clang -cc1 -triple aarch64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name armtest.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=non-leaf -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu generic -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -target-abi aapcs -debugger-tuning=gdb -fdebug-compilation-dir=/home/shuhuai/test -fcoverage-compilation-dir=/home/shuhuai/test -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc-cross/aarch64-linux-gnu/13/../../../../aarch64-linux-gnu/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O1 -ferror-limit 19 -fno-signed-char -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -target-feature +outline-atomics -target-feature -fmv -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/armtest-cd6e57.o -x c armtest.c
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module 'armtest.c'.
4.	Running pass 'Early Machine Loop Invariant Code Motion' on function '@main'
 #0 0x000078b8387a63bf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xda63bf)
 #1 0x000078b8387a44f9 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xda44f9)
 #2 0x000078b8387a6b00 (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xda6b00)
 #3 0x000078b837245330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x000078b83a686c08 (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0x2c86c08)
 #5 0x000078b838b9e9ce (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0x119e9ce)
 #6 0x000078b838b9d470 (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0x119d470)
 #7 0x000078b838b99400 (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0x1199400)
 #8 0x000078b838b826b9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0x11826b9)
 #9 0x000078b8388f7772 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xef7772)
#10 0x000078b8388fd2f4 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xefd2f4)
#11 0x000078b8388f7e9f llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xef7e9f)
#12 0x000078b840e17310 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*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1c17310)
#13 0x000078b84119fa07 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1f9fa07)
#14 0x000078b83fd973d6 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xb973d6)
#15 0x000078b841c0662c clang::FrontendAction::Execute() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x2a0662c)
#16 0x000078b841b830b4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x29830b4)
#17 0x000078b841c8263d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x2a8263d)
#18 0x0000573e0e1fa42e cc1_main(llvm::ArrayRef<char const*>, char const*, void*) build-llvm/tools/clang/stage2-bins/clang/tools/driver/cc1_main.cpp:294:15
#19 0x0000573e0e1f7894 ExecuteCC1Tool build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:365:12
#20 0x0000573e0e1f6a26 clang_main(int, char**, llvm::ToolContext const&) build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:405:12
#21 0x0000573e0e204383 main build-llvm/tools/clang/stage2-bins/build-llvm/tools/clang/stage2-bins/tools/clang/tools/driver/clang-driver.cpp:17:10
#22 0x000078b83722a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#23 0x000078b83722a28b call_init ./csu/../csu/libc-start.c:128:20
#24 0x000078b83722a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#25 0x0000573e0e1f4255 _start (/usr/lib/llvm-18/bin/clang+0xe255)
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
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/armtest-3b582d.c
clang: note: diagnostic msg: /tmp/armtest-3b582d.sh
clang: note: diagnostic msg: 

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

Additional Notes

  1. set optimization level to -O0 will not cause crash
  2. another way to avoid crash is to include arm_neon.h and change the type of a0 from float to float32x4_t
  3. I think the error message may be misleading since the cursor in the message is pointed to the nop instruction. It crashes no matter what the instructions are.

diagnostic_msg.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions