8000 fix: wrong offset in `BB_BRANCH_IF_FLAG_SET` codegen (#21) · oraluben/cpython@b398fab · GitHub
[go: up one dir, main page]

Skip to content

Commit b398fab

Browse files
authored
fix: wrong offset in BB_BRANCH_IF_FLAG_SET codegen (python#21)
1 parent f876fdb commit b398fab

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

Python/bytecodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3355,10 +3355,10 @@ dummy_func(
33553355
_Py_CODEUNIT *t2_nextinstr = NULL;
33563356
_PyBBBranchCache *cache = (_PyBBBranchCache *)next_instr;
33573357
_Py_CODEUNIT *tier1_fallback = NULL;
3358-
33593358
t2_nextinstr = _PyTier2_GenerateNextBB(
33603359
frame, cache->bb_id_tagged, next_instr - 1,
3361-
oparg, &tier1_fallback, bb_test);
3360+
// v We generate from the tier1 consequent BB, so offset (oparg) is 0.
3361+
0, &tier1_fallback, bb_test);
33623362
if (t2_nextinstr == NULL) {
33633363
// Fall back to tier 1.
33643364
next_instr = tier1_fallback;

Python/generated_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
10441044
[BB_BRANCH] = { true, INSTR_FMT_IBC },
10451045
[BB_BRANCH_IF_FLAG_UNSET] = { true, INSTR_FMT_IBC },
10461046
[BB_JUMP_IF_FLAG_UNSET] = { true, INSTR_FMT_IBC },
1047-
[BB_BRANCH_IF_FLAG_SET] = { true, INSTR_FMT_IBC },
1047+
[BB_BRANCH_IF_FLAG_SET] = { true, INSTR_FMT_IXC },
10481048
[BB_JUMP_IF_FLAG_SET] = { true, INSTR_FMT_IBC },
10491049
[BB_JUMP_BACKWARD_LAZY] = { true, INSTR_FMT_IB },
10501050
};

tier2_test.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,20 @@ def f(x):
477477
trigger_tier2(f, (1,))
478478

479479
# As long as it doesn't crash, everything's good.
480+
481+
######################################################################
482+
# Tests for: Tier 2 BB_BRANCH_IF_FLAG_SET codegen #
483+
######################################################################
484+
with TestInfo("tier 2 BB_BRANCH_IF_FLAG_SET codegen"):
485+
# See https://github.com/pylbbv/pylbbv/issues/18 for more information.
486+
def f(x,l):
487+
for _ in l:
488+
_
489+
x+x # Force it to be optimisable
490+
491+
trigger_tier2(f, (1, []))
492+
f(1, [1])
493+
494+
# As long as it doesn't crash, everything's good.
495+
480496
print("Tests completed ^-^")

0 commit comments

Comments
 (0)
0