Skip to content

Commit

Permalink
Fix: Correct target_bb_id in jump array (python#60)
Browse files Browse the repository at this point in the history
* Fix: Correct target_bb_id in jump array

* Doc: Updated doc for add_metadata_to_jump_2d_array
  • Loading branch information
JuliaPoo authored Jul 12, 2023
1 parent e44bf1c commit 22580dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Python/tier2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ IS_BACKWARDS_JUMP_TARGET(PyCodeObject *co, _Py_CODEUNIT *curr)
* This happens when a BB is a backwards jump target.
*
* @param t2_info Tier 2 info of that code object.
* @param meta The BB metadata to add.
* @param target_bb_id The target bb's id
* @param backwards_jump_target Offset (in number of codeunits) from start of code object where
* the backwards jump target is located.
*
Expand All @@ -1518,7 +1518,7 @@ IS_BACKWARDS_JUMP_TARGET(PyCodeObject *co, _Py_CODEUNIT *curr)
* @return 1 for error, 0 for success.
*/
static inline int
add_metadata_to_jump_2d_array(_PyTier2Info *t2_info, _PyTier2BBMetadata *meta,
add_metadata_to_jump_2d_array(_PyTier2Info *t2_info, int target_bb_id,
int backwards_jump_target, _PyTier2TypeContext *starting_context,
_Py_CODEUNIT *tier1_start)
{
Expand All @@ -1545,8 +1545,7 @@ add_metadata_to_jump_2d_array(_PyTier2Info *t2_info, _PyTier2BBMetadata *meta,
#if BB_DEBUG
fprintf(stderr, "Added jump id %d as jump target\n", meta->id);
#endif
t2_info->backward_jump_target_bb_pairs[backward_jump_offset_index][jump_i].id =
meta->id;
t2_info->backward_jump_target_bb_pairs[backward_jump_offset_index][jump_i].id = target_bb_id;
t2_info->backward_jump_target_bb_pairs[backward_jump_offset_index][jump_i].start_type_context = starting_context;
t2_info->backward_jump_target_bb_pairs[backward_jump_offset_index][jump_i].tier1_start = tier1_start;
found = true;
Expand Down Expand Up @@ -2139,7 +2138,7 @@ _PyTier2_Code_DetectAndEmitBB(
assert(start_type_context_copy != NULL);
assert(virtual_tier1_start != NULL);
assert(metas_size >= 0);
if (add_metadata_to_jump_2d_array(t2_info, metas[metas_size],
if (add_metadata_to_jump_2d_array(t2_info, co->_tier2_info->bb_data_curr,
backwards_jump_target_offset, start_type_context_copy,
virtual_tier1_start) < 0) {
_PyTier2TypeContext_Free(starting_type_context);
Expand Down
13 changes: 13 additions & 0 deletions tier2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,19 @@ def f(a, b):
insts = dis.get_instructions(test_typeprop1, tier2=True)
assert [x.opname for x in insts].count("BINARY_OP_ADD_INT_REST") == 2

with TestInfo("Correct target_bb_id in jump table"):
# See https://github.com/pylbbv/pylbbv/issues/43 for more information

def f(x, l):
for i in l:
if i:
break
x+x

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

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

print("Regression tests...Done!")

print("Tests completed ^-^")

0 comments on commit 22580dc

Please sign in to comment.