Skip to content

Commit 46f823b

Browse files
gh-132732: Clear errors in JIT optimizer on error (GH-136048)
1 parent 26cfb17 commit 46f823b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Python/optimizer_analysis.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ const uint16_t op_without_decref_inputs[MAX_UOP_ID + 1] = {
462462
[_BINARY_OP_SUBTRACT_FLOAT] = _BINARY_OP_SUBTRACT_FLOAT__NO_DECREF_INPUTS,
463463
};
464464

465-
/* 1 for success, 0 for not ready, cannot error at the moment. */
465+
/* >0 (length) for success, 0 for not ready, clears all possible errors. */
466466
static int
467467
optimize_uops(
468468
PyCodeObject *co,
@@ -472,6 +472,7 @@ optimize_uops(
472472
_PyBloomFilter *dependencies
473473
)
474474
{
475+
assert(!PyErr_Occurred());
475476

476477
JitOptContext context;
477478
JitOptContext *ctx = &context;
@@ -555,7 +556,11 @@ optimize_uops(
555556
OPT_ERROR_IN_OPCODE(opcode);
556557
}
557558
_Py_uop_abstractcontext_fini(ctx);
558-
return -1;
559+
560+
assert(PyErr_Occurred());
561+
PyErr_Clear();
562+
563+
return 0;
559564

560565
}
561566

@@ -702,10 +707,12 @@ _Py_uop_analyze_and_optimize(
702707
_PyFrame_GetCode(frame), buffer,
703708
length, curr_stacklen, dependencies);
704709

705-
if (length <= 0) {
710+
if (length == 0) {
706711
return length;
707712
}
708713

714+
assert(length > 0);
715+
709716
length = remove_unneeded_uops(buffer, length);
710717
assert(length > 0);
711718

0 commit comments

Comments
 (0)