[clang] [llvm] [Clang][BPF] Allow sign/zero extension for call parameters with int/uint types (PR #84874)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 13 08:32:35 PDT 2024


eddyz87 wrote:

@yonghong-song , if I understand @efriedma-quic correctly (thank you for explanations), the following fragment is not RISC-V ABI conformant:

```
$ cat u.c
void foo(unsigned);
void bar(unsigned a, unsigned b) {
  foo(a + b);
}

       1:       67 02 00 00 20 00 00 00 r2 <<= 0x20
       2:       77 02 00 00 20 00 00 00 r2 >>= 0x20
       3:       bf 21 00 00 00 00 00 00 r1 = r2
       4:       85 10 00 00 ff ff ff ff call -0x1
```

The `r1` would be zero extended, while to be ABI conformant it has to be sign extended, as for RV64 the 31-st bit should be the same as upper 32 bits. The fact that decision to zero or sign extend the argument depends on the architecture means that this extension has to be done at JIT time (meaning that BTF is mandatory) or be a part of kfunc.

https://github.com/llvm/llvm-project/pull/84874


More information about the cfe-commits mailing list