[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 09:53:50 PDT 2024


yonghong-song 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.

If the verifier keeps the same verifier_zext flag for 'r1 = r2', then we should be okay. If not, then we have a problem. I need to double check.

I guess I will remove UInt support from this patch since it does not improve anything and may risk break something. We can add it back later if needed and other issue (with riscv) is clarified/resolved.

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


More information about the cfe-commits mailing list