llvm / llvm/llvm-project

BPF: stack args cause backend to crash without optimization

Open
#205,647 3 comments 0 reactions 0 assignees View on GitHub
backend:BPF confirmed crash-on-valid regression:22
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

When compiling the following code using `clang` with the BPF target, but without enabling optimizations, the backend crashes with the error `fatal error: error in backend: Unsupported instruction : >`.
```c
void f(int, int, int, int, int, int);

int main(void)
{
f(0, 0, 0, 0, 0, 0);
return 0;
}
```
A `store_stack_arg -8, r1` instruction is emitted for the sixth argument, but because the `BPFMIPreEmitPeephole` pass is only added when optimization is enabled, the pseudoinstruction is not replaced with actual stores. Running `llc -O0` on the equivalent IR also shows that `store_stack_arg` appears in the assembly output.

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with the shown C program using clang and the BPF target, then compare it with llc -O0 on equivalent IR. Inspect the BPFMIPreEmitPeephole pass and the handling of store_stack_arg; done means unoptimized output no longer leaves the pseudoinstruction unresolved and the backend no longer crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.