GH-128534: Fix behavior of branch monitoring for async for (GH-130847)

* Both branches in a pair now have a common source and are included in co_branches
This commit is contained in:
Mark Shannon 2025-03-07 14:30:31 +00:00 committed by GitHub
parent e5527f2cdd
commit 89df62c120
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 235 additions and 154 deletions

View file

@ -3109,6 +3109,14 @@ branchesiter_next(branchesiterator *bi)
int not_taken = next_offset + 1;
bi->bi_offset = not_taken;
return int_triple(offset*2, not_taken*2, (next_offset + oparg)*2);
case END_ASYNC_FOR:
oparg = (oparg << 8) | inst.op.arg;
int src_offset = next_offset - oparg;
bi->bi_offset = next_offset;
assert(_Py_GetBaseCodeUnit(bi->bi_code, src_offset).op.code == END_SEND);
assert(_Py_GetBaseCodeUnit(bi->bi_code, src_offset+1).op.code == NOT_TAKEN);
not_taken = src_offset + 2;
return int_triple(src_offset *2, not_taken*2, next_offset*2);
default:
oparg = 0;
}