<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/153442>153442</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang crashes when compiling aarch64 inline assembly with optimization enabled
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
csh-lovenico
</td>
</tr>
</table>
<pre>
## 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
```c
// 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:
```bash
clang --target=aarch64-linux-gnu armtest.c -O1
```
for comparison, gcc works well:
```bash
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](https://github.com/user-attachments/files/21758221/diagnostic_msg.zip)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8Wl9z2yrT_zTkZgePhGRbvsiF88ennWmfZJqc57n0ILSSeYpALyAnOZ_-HZBc2U562tPmfTueWIZl98ey-wOx5c7JRiNekvkVmd9c8N7vjL0UbkeV2aOWwlyUpnq5JCwjLINbvZfW6Ba1J8maJOs_y177HoTiuoE9WieNhrSYpbMMCCvSPvanhK1Isn7ktkFPsjU8F4vtIqedoErq_pk2ug_9O4u8gtZUqIJUZ5x8Jsn6o3aeK4XVjbShnbBN7yxhm1LqAYbp0HIvdQPuxXlsg9RgGlg-S3KSrAeI0oE8aIPehRG887NBS_gM8_wstWy5gi_YWVP1wodp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