Skip to content

Cranelift: riscv64: C.J veneer range overflow #12811

@s0me0ne-unkn0wn

Description

@s0me0ne-unkn0wn

Summary

When compiling large functions targeting riscv64gc with compressed instructions (Zca) enabled, emit_veneer() panics because the veneer is placed too far from the original C.J.

The island emission deadline mechanism is supposed to force island emission before any label reference goes out of range, but, presumably, the deadline calculation doesn't account for the very small range of C.J when traps and constants are flushed before veneers — these can push the veneer past the 2 KiB limit.

.clif Test Case

rvcjump_bug_reduced.clif.gz

Steps to Reproduce

$ clif-util test rvcjump_bug_reduced.clif

Expected Results

Success

Actual Results

thread 'worker #0' panicked at cranelift/codegen/src/isa/riscv64/inst/mod.rs:1759:9:
RVCJump offset '2048' use_offset:'7416' label_offset:'9464'  must not exceed max range.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2026-03-20T19:04:21Z ERROR cranelift_filetests::concurrent] FAIL: panicked in worker #0: RVCJump offset '2048' use_offset:'7416' label_offset:'9464'  must not exceed max range.
FAIL rvcjump_bug_reduced.clif: panicked in worker #0: RVCJump offset '2048' use_offset:'7416' label_offset:'9464'  must not exceed max range.
1 tests
Error: 1 failure

Versions and Environment

Cranelift version or commit: 0.122.0

Operating system: Linux Manjaro

Architecture: x86_64 cross-compiling to riscv64gc

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixingcraneliftIssues related to the Cranelift code generatorcranelift:area:riscv64Issues related to the RISC-V 64 backend.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions