0xPolygonMiden / compiler

Compiler from MidenIR to Miden Assembly
MIT License
63 stars 21 forks source link

Fix codegen for casting `i32 <-> u32` and `i32 -> u64` #250

Closed greenhat closed 2 months ago

greenhat commented 2 months ago

As described in https://github.com/0xPolygonMiden/compiler/pull/232#discussion_r1672517515

I've looked into this issue, and the fix is to remove the call to assert_unsigned_int32 from cast when casting from i32 to u32, from u32 to i32, and from i32 to u64; and replace it with a call to a new helper called assert_i32, see the implementation of assert_i64 in emit/int64.rs for how to implement it.

The problem is that the assert_unsigned_int32 helper is intended to assert that the sign bit of a 32-bit value is unset, not to assert that the value is non-negative, which is how we are using it in cast.

All the other uses of assert_unsigned_int32 are correct

bitwalker commented 2 months ago

Fixed in #251