Repository navigation
[mypyc] Emit unsigned casts for i8 and i16 operands - #22479
Open
Jahongir-Qurbonov wants to merge 2 commits into
Open
Jahongir-Qurbonov wants to merge 2 commits into
Jahongir-Qurbonov wants to merge 2 commits into
Conversation
emit_unsigned_int_cast only handled 32-bit and 64-bit operands, so an unsigned comparison (ULT etc.) or a zero-extending Extend with an i8 or i16 operand was emitted without a cast. C then compared or extended the value as signed, e.g. an i8 value of -1 extended to 0xffffffffffffffff instead of 0xff, and -1 < 5 was true for an unsigned comparison. The current IR builder doesn't generate such ops, but they are valid IR and easy to produce when adding new native int operations, so cast to uint8_t and uint16_t like we already do for the wider types.
p-sawicki
pushed a commit
that referenced
this pull request
Nov 20, 2026
`test_long_unsigned`, `test_long_signed` and `test_extend` in `test_emitfunc.py` created their own `int64`/`int32` registers named `a`, although `setUp` already defines `self.i64` and `self.i32` registers for this purpose and the other tests use them. Use those instead. This is a test-only cleanup with no functional changes. (This touches the same lines in `test_extend` as #22479, so I'll merge master into whichever lands second.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
emit_unsigned_int_castonly handled 32-bit and 64-bit operands, so an unsigned comparison (ULTetc.) or a zero-extendingExtendwith ani8ori16operand was emitted without a cast. C then compared or extended the value as signed: for example, ani8value of -1 was zero-"extended" to0xffffffffffffffffinstead of0xff, and-1 < 5was true for an unsigned comparison.The IR builder doesn't currently generate such ops, but they are valid IR and easy to produce when adding new native int operations (I ran into this while working on #22471, which uses signed comparisons to avoid it). This casts to
uint8_tanduint16_t, like we already do for the wider types.Added emitfunc tests for
i8/i16unsigned comparisons and zero extension.