Repository navigation
Commit 8d46f83
committed
Core: Fix loop edge cases the lowering got wrong
- `pass` is accepted as a statement, the natural body of a loop run for its
side effects.
- Falling off the end of a function returns 0 in the function's own return
type. After `while True` that block is unreachable, but a c_int32 function
still emitted `ret i64 0`, which llc rejected.
- A range() step other than 1 could wrap the counter past INT64_MAX or
UINT64_MAX back inside the range and loop forever. The step block now ends
the loop when the distance left to stop, exact as an unsigned number, is
no longer than the step. That is a normal exit, so the else-branch runs.
Steps of 1 cannot overshoot and keep the plain loop, so the helper-bounded
loop the verifier walks is unchanged.
- A step of 2**64 or more no longer truncates to 0: it is a compile error,
since it does not fit the counter. Steps from 2**63 up are emitted by
their bits.
- The counter's signedness folds each bound into a signed 64-bit type rather
than joining the bounds alone, so only a c_uint64 bound makes it unsigned:
range(-1, n) over a c_uint32 n runs 4 times, as in C with an __s64 counter.1 parent 89b7eb6 commit 8d46f83
2 files changed
Lines changed: 41 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
106 | 109 | | |
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
113 | | - | |
114 | | - | |
| 116 | + | |
| 117 | + | |
115 | 118 | | |
116 | 119 | | |
117 | 120 | | |
| |||
191 | 194 | | |
192 | 195 | | |
193 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
194 | 202 | | |
195 | 203 | | |
196 | 204 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
491 | 491 | | |
492 | 492 | | |
493 | 493 | | |
494 | | - | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
495 | 510 | | |
496 | 511 | | |
497 | 512 | | |
| |||
509 | 524 | | |
510 | 525 | | |
511 | 526 | | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
512 | 534 | | |
513 | 535 | | |
514 | 536 | | |
| |||
595 | 617 | | |
596 | 618 | | |
597 | 619 | | |
| 620 | + | |
| 621 | + | |
598 | 622 | | |
599 | 623 | | |
600 | 624 | | |
| |||
734 | 758 | | |
735 | 759 | | |
736 | 760 | | |
737 | | - | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
738 | 766 | | |
739 | 767 | | |
740 | 768 | | |
| |||
0 commit comments