[m-rev.] for review: Don't cast int32/uint32 to MR_Word in foreign code input assignments.
Zoltan Somogyi
zoltan.somogyi at runbox.com
Thu Oct 1 14:35:44 AEST 2026
On Thu, 1 Oct 2026 14:13:29 +1000, Peter Wang <novalazy at gmail.com> wrote:
> This fixes gcc warnings on 64-bit platforms of the form:
>
> warning: overflow in conversion from ‘long long unsigned int’ to
> ‘int32_t’ {aka ‘int’} changes value from ‘18446744071562067968’ to
> ‘-2147483648’ [-Woverflow]
>
> for the generated code:
>
> I32 = ((MR_Word) INT32_MIN);
>
> compiler/llds_out_instr.m:
> In output_foreign_proc_inputs, output int32/uint32 input values
> without a cast to MR_Word.
For this to work by design instead of by accident, we have to ensure that
the type of the integer we output here is the same as, or at least is
automatically castable to, the declared type of the foreign language
variable representing that input arg. That type is decided by whatever
code sets the third field of the foreign_proc_arg_decl given to
output_foreign_proc_decls, which is not in that file. You should find
that code, and add a link to it here.
I am surprised that we do not treat 8 and 16 bit ints/uints the same way
we now treat 32 and 64 bit. Why? If writing them out as lt_word is fine,
there should be a comment explaining *why* it is fine.
Zoltan.
More information about the reviews
mailing list