From 56caf1b29a9896570463002ca805d72c6a1a593d Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Tue, 3 Nov 2020 16:22:20 +0100 Subject: [PATCH] Add extension marker to i32 arguments of builtin functions Some platform ABIs require i32 values to be zero- or sign-extended to the full register width. The extension is implemented by the cranelift codegen backend, but this happens only if the appropriate "uext" or "sext" attribute is present in the cranelift IR. For calls to builtin functions, that IR is synthesized by the code in func_environ.rs -- to ensure correct codegen for the target ABI, this code needs to add those attributes as necessary. --- crates/cranelift/src/func_environ.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs index efe1e5beb6..88d37ab776 100644 --- a/crates/cranelift/src/func_environ.rs +++ b/crates/cranelift/src/func_environ.rs @@ -69,7 +69,16 @@ macro_rules! declare_function_signatures { } fn i32(&self) -> AbiParam { - AbiParam::new(I32) + // Some platform ABIs require i32 values to be zero- or sign- + // extended to the full register width. We need to indicate + // this here by using the appropriate .uext or .sext attribute. + // The attribute can be added unconditionally; platforms whose + // ABI does not require such extensions will simply ignore it. + // Note that currently all i32 arguments or return values used + // by builtin functions are unsigned, so we always use .uext. + // If that ever changes, we will have to add a second type + // marker here. + AbiParam::new(I32).uext() } $(