| Issue |
243160
|
| Summary |
[BPF] Assertion in PrintAsmMemoryOperand with %a on a register operand
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
mu-mu-mu
|
On BPF, using the `%a` operand modifier on a register operand (a pointer in `"r"`) crashes an assertions build in `BPFAsmPrinter::PrintAsmMemoryOperand()`.
### Reproducer
```c
void f(int *p)
{
__asm__ volatile("# %a0" : : "r"(p));
}
```
### Actual behavior
Clang crashes with an assertion failure in `BPFAsmPrinter::PrintAsmMemoryOperand()`:
```console
$ clang --version
clang version 24.0.0git
Target: unknown
Thread model: posix
InstalledDir: /workdir/llvm-bpf-assert-c0005dfe81fe/bin
Build config: +assertions
$ clang --target=bpf -c test.c
```
Crash reproducer `test-dadfa2.c`:
```c
# 1 "<built-in>"
# 1 "test.c"
void f(int *p)
{
__asm__ volatile("# %a0" : : "r"(p));
}
```
Crash reproducer `test-dadfa2.sh`:
```sh
# Crash reproducer for clang version 24.0.0git
# Driver args: "--target=bpf" "-c" "test.c"
# Original command: "/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang-24" "-cc1" "-triple" "bpf" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.c" "-mrelocation-model" "static" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/workdir/reproducer" "-fcoverage-compilation-dir=/workdir/reproducer" "-resource-dir" "/workdir/llvm-bpf-assert-c0005dfe81fe/lib/clang/24" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fno-color-diagnostics" "-faddrsig" "-o" "test.o" "-x" "c" "test.c"
"/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang-24" "-cc1" "-triple" "bpf" "-emit-obj" "-disable-free" "-clear-ast-before-backend" "-main-file-name" "test.c" "-mrelocation-model" "static" "-mframe-pointer=all" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-debugger-tuning=gdb" "-fdebug-compilation-dir=/workdir/reproducer" "-fcoverage-compilation-dir=/workdir/reproducer" "-ferror-limit" "19" "-fgnuc-version=4.2.1" "-fskip-odr-check-in-gmf" "-fno-color-diagnostics" "-faddrsig" "-x" "c" "test-dadfa2.c"
```
### Expected behavior
The code should compile successfully. The inline assembly only expands `%a0` inside an assembly comment; it does not emit any instructions.
clang (assertions trunk): https://godbolt.org/z/1s5MnGqz7
### Output (local paths replaced with `/workdir/...`)
```console
clang: /workdir/llvm-project/llvm/lib/Target/BPF/BPFAsmPrinter.cpp:170: virtual bool llvm::BPFAsmPrinter::PrintAsmMemoryOperand(const llvm::MachineInstr *, unsigned int, const char *, llvm::raw_ostream &): Assertion `OffsetMO.isImm() && "Unexpected offset for inline asm memory operand."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang --target=bpf -c test.c
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'test.c'.
4. Running pass 'BPF Assembly Printer' on function '@f'
#0 0x00005611d119a28a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x3ddd28a)
#1 0x00005611d119718e llvm::sys::RunSignalHandlers() (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x3dda18e)
#2 0x00005611d1198da8 llvm::sys::CleanupOnSignal(unsigned long) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x3ddbda8)
#3 0x00005611d10f83ec CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007fdb3439c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007fdb343f09fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x00007fdb3439c476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x00007fdb343827f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x00007fdb3438271b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x00007fdb34393e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x00005611d00d4eec llvm::BPFAsmPrinter::PrintAsmMemoryOperand(llvm::MachineInstr const*, unsigned int, char const*, llvm::raw_ostream&) BPFAsmPrinter.cpp:0:0
#11 0x00005611d2cbdaeb llvm::AsmPrinter::PrintAsmOperand(llvm::MachineInstr const*, unsigned int, char const*, llvm::raw_ostream&) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x5900aeb)
#12 0x00005611d2cbce24 llvm::AsmPrinter::emitInlineAsm(llvm::MachineInstr const*) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x58ffe24)
#13 0x00005611d2c9f41d llvm::AsmPrinter::emitFunctionBody() (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x58e241d)
#14 0x00005611d00d5945 llvm::AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) BPFAsmPrinter.cpp:0:0
#15 0x00005611d05019e6 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x31449e6)
#16 0x00005611d0bdcbac llvm::FPPassManager::runOnFunction(llvm::Function&) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x381fbac)
#17 0x00005611d0be5181 llvm::FPPassManager::runOnModule(llvm::Module&) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x3828181)
#18 0x00005611d0bdd8fa llvm::legacy::PassManagerImpl::run(llvm::Module&) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x38208fa)
#19 0x00005611d2c698d8 llvm::runCodeGenPipeline(llvm::TargetMachine&, llvm::Module&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, bool, bool, llvm::ModuleSummaryIndex const*, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x58ac8d8)
#20 0x00005611d19bb2c9 (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >, clang::BackendConsumer*) BackendUtil.cpp:0:0
#21 0x00005611d19b8fa2 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, 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*) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x45fbfa2)
#22 0x00005611d19dda76 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x4620a76)
#23 0x00005611d3828ed7 clang::ParseAST(clang::Sema&, bool, bool) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x646bed7)
#24 0x00005611d1ffae86 clang::FrontendAction::Execute() (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x4c3de86)
#25 0x00005611d1f65b5f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x4ba8b5f)
#26 0x00005611d20ca375 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x4d0d375)
#27 0x00005611d00c8491 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x2d0b491)
#28 0x00005611d00c4546 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#29 0x00005611d00c6953 int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::$_0>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#30 0x00005611d1d9c289 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::$_1>(long) Job.cpp:0:0
#31 0x00005611d10f80fb llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x3d3b0fb)
#32 0x00005611d1d9b683 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x49de683)
#33 0x00005611d1d56363 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x4999363)
#34 0x00005611d1d56892 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&, bool) const (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x4999892)
#35 0x00005611d1d7a368 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x49bd368)
#36 0x00005611d00c3b94 clang_main(int, char**, llvm::ToolContext const&) (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x2d06b94)
#37 0x00005611d00d40a6 main (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x2d170a6)
#38 0x00007fdb34383d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#39 0x00007fdb34383e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#40 0x00005611d00c1f65 _start (/workdir/llvm-bpf-assert-c0005dfe81fe/bin/clang+0x2d04f65)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 24.0.0git
Target: bpf
Thread model: posix
InstalledDir: /workdir/llvm-bpf-assert-c0005dfe81fe/bin
Build config: +assertions
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING CRASH REPRODUCER FILES TO THE BUG REPORT:
clang: note: diagnostic msg: /tmp/test-dadfa2.c
clang: note: diagnostic msg: /tmp/test-dadfa2.sh
clang: note: diagnostic msg:
********************
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs