Commit a2e354b
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 a2e354b
1 file changed
+20
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
315 | | - | |
| 314 | + | |
316 | 315 | | |
317 | 316 | | |
318 | 317 | | |
| |||
343 | 342 | | |
344 | 343 | | |
345 | 344 | | |
346 | | - | |
347 | | - | |
348 | 345 | | |
349 | 346 | | |
350 | 347 | | |
| |||
417 | 414 | | |
418 | 415 | | |
419 | 416 | | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
420 | 436 | | |
421 | 437 | | |
422 | 438 | | |
| |||
0 commit comments