Commit f47bcc9
committed
W22 fix v2: populate n_in==0 in-state UNCOUNTED, not OWNED
The 66850a4 fix populated env->live_regs from liveness analysis for
n_in==0 blocks but marked each live-in reg as PHX_REF_OWNED. That
unblocked yield-from compilation but introduced an over-decref of
LoadArg-defined registers (gdb 18:20Z + sys.getrefcount instrumentation:
match-statement test parameter list lost 1 refcount per JIT call →
use-after-free → SIGSEGV in test framework's PyObject_Repr).
Root cause of the over-decref: refcount_pass processes EVERY n_in==0
block, not just the function entry / yield-resume blocks. DCE-pending
dead blocks (and similar transient blocks before cleanup) also appear
n_in==0, and liveness reports their LoadArg-defined live-in registers.
Marking those OWNED makes refcount_pass emit decref(reg) at the dead
block's exit. Even though the block is dead, the decref instruction
gets compiled and (somehow — probably via control-flow paths the CFG
does not show) reaches runtime once per call.
Fix: keep populating env->live_regs (preserves the n_in==0 NULL-deref
fix at refcount_pass_c.c:716) but leave each rstate at the default
PHX_REF_UNCOUNTED kind. The function-entry path silently overwrites
the entry via processOutput when LoadArg defines the reg; the
yield-resume path's compiled code reads the runtime-restored value
without decref'ing it, so UNCOUNTED is safe (no leak — the runtime's
resume code owns the ref).
Verification at HEAD post-fix:
/tmp/refcount_track.py: parameter list refcount delta = 0 (was -1)
/tmp/repro_min3.py: yield-from PASS, gen_yieldfrom is_jit_compiled=True
/tmp/repro_match_unittest.py: PASS
python -m unittest test_phoenix_jit_comparisons.test_match_sequence_guard: PASS
await_caller still has a separate deopt-side issue (deopt.cpp:478
'register v27 not live' at YieldFrom FrameState live_regs) — different
bug class, continuing GDB.1 parent 66850a4 commit f47bcc9
1 file changed
Lines changed: 39 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
498 | 498 | | |
499 | 499 | | |
500 | 500 | | |
501 | | - | |
502 | | - | |
| 501 | + | |
503 | 502 | | |
504 | 503 | | |
505 | 504 | | |
506 | 505 | | |
507 | | - | |
508 | | - | |
509 | | - | |
510 | | - | |
511 | | - | |
512 | | - | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
518 | 518 | | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
524 | 528 | | |
525 | 529 | | |
526 | 530 | | |
| |||
534 | 538 | | |
535 | 539 | | |
536 | 540 | | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
544 | 558 | | |
545 | 559 | | |
546 | 560 | | |
| |||
0 commit comments