Skip to content

Commit

Permalink
fix: wrong offset in BB_BRANCH_IF_FLAG_SET codegen (python#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliaPoo authored Jun 4, 2023
1 parent f876fdb commit b398fab
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3355,10 +3355,10 @@ dummy_func(
_Py_CODEUNIT *t2_nextinstr = NULL;
_PyBBBranchCache *cache = (_PyBBBranchCache *)next_instr;
_Py_CODEUNIT *tier1_fallback = NULL;

t2_nextinstr = _PyTier2_GenerateNextBB(
frame, cache->bb_id_tagged, next_instr - 1,
oparg, &tier1_fallback, bb_test);
// v We generate from the tier1 consequent BB, so offset (oparg) is 0.
0, &tier1_fallback, bb_test);
if (t2_nextinstr == NULL) {
// Fall back to tier 1.
next_instr = tier1_fallback;
Expand Down
2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/opcode_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ const struct opcode_metadata _PyOpcode_opcode_metadata[256] = {
[BB_BRANCH] = { true, INSTR_FMT_IBC },
[BB_BRANCH_IF_FLAG_UNSET] = { true, INSTR_FMT_IBC },
[BB_JUMP_IF_FLAG_UNSET] = { true, INSTR_FMT_IBC },
[BB_BRANCH_IF_FLAG_SET] = { true, INSTR_FMT_IBC },
[BB_BRANCH_IF_FLAG_SET] = { true, INSTR_FMT_IXC },
[BB_JUMP_IF_FLAG_SET] = { true, INSTR_FMT_IBC },
[BB_JUMP_BACKWARD_LAZY] = { true, INSTR_FMT_IB },
};
Expand Down
16 changes: 16 additions & 0 deletions tier2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,20 @@ def f(x):
trigger_tier2(f, (1,))

# As long as it doesn't crash, everything's good.

######################################################################
# Tests for: Tier 2 BB_BRANCH_IF_FLAG_SET codegen #
######################################################################
with TestInfo("tier 2 BB_BRANCH_IF_FLAG_SET codegen"):
# See https://github.com/pylbbv/pylbbv/issues/18 for more information.
def f(x,l):
for _ in l:
_
x+x # Force it to be optimisable

trigger_tier2(f, (1, []))
f(1, [1])

# As long as it doesn't crash, everything's good.

print("Tests completed ^-^")

0 comments on commit b398fab

Please sign in to comment.