Repository navigation
Description
Problem
RISC-V64 C interoperability silently passes incorrect values for aggregates that contain floating-point fields but do not qualify for floating-point register passing. A three-float structure fails in both call directions. Two-double structures also fail after seven preceding double arguments, and mixed structures fail after integer argument registers are exhausted.
classify_param_riscv64 returns the original aggregate whenever its leaves are not all integers/pointers, without accounting for available argument registers. LLVM then receives a transport type that differs from Clang. The RISC-V psABI requires fallback to the integer convention when the floating-point eligibility/register conditions are not met.
Starting points: llvm/src/codegen/abi_c/riscv.rs, llvm/src/codegen/abi_c.rs, tests/fixtures/riscv64_psabi/interop.wave.
Reproduction
Tested at 4c3372157d8889fa8bbef0a7ccd2e72aab1c5c6c on Linux amd64 with the checkout-built Wave compiler, LLVM/Clang 21.1.8 and QEMU user emulation.
Save as probe.c and probe.wave:
struct S { float a,b,c; };
int c_check(struct S v) { return (v.a == 1.5 && v.b == 2.5 && v.c == 3.5) ? 0 : 11; }
extern int wave_check(struct S v);
int c_exports(void) { return wave_check((struct S){1.5,2.5,3.5}); }struct S { a: f32; b: f32; c: f32; }
extern(c) fun c_check(v: S) -> i32;
extern(c) fun c_exports() -> i32;
export(c) fun wave_check(v: S) -> i32 { if (v.a == 1.5 && v.b == 2.5 && v.c == 3.5) { return 0; } return 12; }
fun main() -> i32 { var code: i32 = c_check(S { a: 1.5, b: 2.5, c: 3.5 }); if (code != 0) { return code; } return c_exports(); }
Build the compiler with LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 cargo build --locked --jobs 2 (adjust the LLVM prefix for your host). Run from the repository root:
mkdir -p /tmp/wave-abi-audit
clang --target=riscv64-unknown-linux-gnu -O0 -ffreestanding -fno-builtin -c probe.c -o /tmp/wave-abi-audit/c.o
clang --target=riscv64-unknown-linux-gnu -O0 -ffreestanding -fno-builtin -c tests/fixtures/linux_case_runtime/start.c -o /tmp/wave-abi-audit/start.o
target/debug/wavec build probe.wave --target riscv64-unknown-linux-gnu --emit=obj,ir -O0 --out-dir /tmp/wave-abi-audit
clang --target=riscv64-unknown-linux-gnu -fuse-ld=lld -nostdlib -static -Wl,-e,_start /tmp/wave-abi-audit/start.o /tmp/wave-abi-audit/c.o /tmp/wave-abi-audit/probe.o -o /tmp/wave-abi-audit/run
qemu-riscv64 /tmp/wave-abi-audit/runExpected exit 0; observed exit 11 at O0 and O2. Replacing main with return c_exports(); independently tests C-to-Wave calls and exits 12 at both optimization levels.
Scope
Implement aggregate eligibility and register accounting for the supported RV64 ABIs in both extern calls and C exports. Preserve correct object layout while changing ABI transport. Keep existing successful scalar and eligible aggregate cases.
Also reproduced: pointer-plus-double, three floats, two doubles after seven doubles, and double-plus-i64 after eight i64 arguments. The same audit cases pass on Linux amd64, ARM64 and LoongArch64. This is a concrete compiler defect, separate from Wave ABI design (#350).
Difficulty: hard.
Completion criteria
- The minimal fixture passes in both directions at O0/O2 under QEMU or native RISC-V64.
- Compare transport with Clang for eligible/ineligible shapes and GP/FP exhaustion, including sret accounting.
- Exercise lp64, lp64f and lp64d without regressing existing ABI-mode fixtures.
Activity
Stabilize compiler inputs, target ABIs, and freestanding runtimes (#798)