Commit 22f64f2
Fix UInt8/UInt16 comparison after wrapping arithmetic (#694)
Comparisons (Eq, Neq, Lt, Lte, Gt, Gte) on UInt8/UInt16 after wrapping
arithmetic (add_mod, sub_mod, mul_mod, shift_left, xor, or, etc.) produced
wrong C code. The uint32 intermediate from mk_arith was compared directly
without masking back to the original width.
For example, (255uy +%^ 1uy) = 0uy generated:
(uint32_t)255 + (uint32_t)1 == 0 => 256 == 0 => false (WRONG)
Fix: handle comparisons in mk_expr (not mk_arith) with a dedicated pattern
that only widens+masks operands containing arithmetic subexpressions.
Atomic operands (variables, field accesses, etc.) are compared at their
native width without unnecessary casts.
Now generates:
simple: a == b (no casts)
arith: ((uint32_t)a + (uint32_t)b & 0xFFU) == c (only arith side)
Fixes #694. Also fixes #689, #691, #692, #693 (same root cause).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent d859556 commit 22f64f2
1 file changed
+18
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
420 | 438 | | |
421 | 439 | | |
422 | 440 | | |
| |||
0 commit comments