Skip to content

Conversation

@marxin
Copy link
Contributor

@marxin marxin commented Jan 16, 2026

There's a special requirement for the RISC-V SysV ABI:
https://five-embeddev.com/riscv-user-isa-manual/Priv-v1.12/rv64.html

The compiler and calling convention maintain an invariant that all 32-bit values are held in a sign-extended format in 64-bit registers.
Even 32-bit unsigned integers extend bit 31 into bits 63 through 32. Consequently, conversion between unsigned and signed 32-bit integers
is a no-op, as is conversion from a signed 32-bit integer to a signed 64-bit integer.

So far, we've been using X86_64SystemV for the RISC-V ABI, and so I copied it into a separate one, where extra param attributes are added. That's something we must address as part of #5943. On top of that I decided to put some common functionality into the Abi trait itself.

@wakabat can you give it a try?

Fixes: #5977

Copilot AI review requested due to automatic review settings January 16, 2026 13:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes calling conventions for the i32 type on RISC-V 64-bit platforms to comply with the RISC-V SysV ABI requirement that all 32-bit values must be held in sign-extended format in 64-bit registers.

Changes:

  • Introduces a new RISC-V SystemV ABI implementation with proper handling of i32 sign-extension requirements
  • Adds signext and noundef attributes to all i32 parameters in function declarations and call sites for RISC-V 64-bit targets
  • Refactors common ABI functionality into default trait implementations to reduce code duplication

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
lib/compiler-llvm/src/abi/riscv_systemv.rs New file implementing RISC-V SystemV ABI with i32 sign-extension handling
lib/compiler-llvm/src/abi/mod.rs Refactors common ABI methods into default trait implementations; adds RISC-V ABI selection
lib/compiler-llvm/src/abi/x86_64_systemv.rs Removes duplicate code now in default trait implementations
lib/compiler-llvm/src/abi/aarch64_systemv.rs Removes duplicate code now in default trait implementations
lib/compiler-llvm/src/translator/intrinsics.rs Adds target_triple parameter and applies i32 attributes to intrinsic functions for RISC-V
lib/compiler-llvm/src/translator/code.rs Adds build_call_with_param_attributes helper to apply i32 attributes at call sites for RISC-V
lib/compiler-llvm/src/trampoline/wasm.rs Updates Intrinsics::declare calls with new target_triple parameter

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +498 to +515
for (i, param) in ty.get_param_types().iter().enumerate() {
if param == &i32_ty_basic_md {
function.add_attribute(
AttributeLoc::Param(i as u32),
context.create_enum_attribute(
Attribute::get_named_enum_kind_id("signext"),
0,
),
);
function.add_attribute(
AttributeLoc::Param(i as u32),
context.create_enum_attribute(
Attribute::get_named_enum_kind_id("noundef"),
0,
),
);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find a bit strange that this logic lives here, it feels a bit of a hack.
Do you think this could be improved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! We can do better by using the https://thedan64.github.io/inkwell/inkwell/intrinsics/struct.Intrinsic.html#method.find API, that should give us a properly annotated declaration that hopefully takes target ABI into account.

marxin and others added 3 commits January 19, 2026 10:40
@marxin marxin added this to the v7.0 milestone Jan 19, 2026
@wakabat
Copy link
Contributor

wakabat commented Jan 20, 2026

Hey thanks for this change! I have run all the tests on our side using Rust 1.92.0, and they all pass. So as far as our tests, this change did resolve the bug in #5977

@marxin
Copy link
Contributor Author

marxin commented Jan 20, 2026

Cool, thanks for the confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wasmer's LLVM compiler generates code to pass 64-bit value to memory_copy

4 participants