Skip to content

Commit e648644

Browse files
Add test to cases generator
1 parent a78813d commit e648644

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,7 @@ def testfunc(n):
24542454
def test_binary_op_constant_evaluate(self):
24552455
def testfunc(n):
24562456
for _ in range(n):
2457-
a = 2 ** 65
2457+
2 ** 65
24582458

24592459
testfunc(TIER2_THRESHOLD)
24602460

Lib/test/test_generated_cases.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,6 +2398,53 @@ def test_replace_opcode_uop_body_copied_in_complex(self):
23982398
"""
23992399
self.run_cases_test(input, input2, output)
24002400

2401+
def test_replace_opcode_escaping_uop_body_copied_in_complex(self):
2402+
input = """
2403+
pure op(OP, (foo -- res)) {
2404+
if (foo) {
2405+
res = ESCAPING_CODE(foo);
2406+
}
2407+
else {
2408+
res = 1;
2409+
}
2410+
}
2411+
"""
2412+
input2 = """
2413+
op(OP, (foo -- res)) {
2414+
REPLACE_OPCODE_IF_EVALUATES_PURE(foo);
2415+
res = sym_new_known(ctx, foo);
2416+
}
2417+
"""
2418+
output = """
2419+
case OP: {
2420+
JitOptRef foo;
2421+
JitOptRef res;
2422+
foo = stack_pointer[-1];
2423+
if (
2424+
sym_is_safe_const(ctx, foo)
2425+
) {
2426+
JitOptRef foo_sym = foo;
2427+
_PyStackRef foo = sym_get_const_as_stackref(ctx, foo_sym);
2428+
_PyStackRef res_stackref;
2429+
/* Start of uop copied from bytecodes for constant evaluation */
2430+
if (foo) {
2431+
res_stackref = ESCAPING_CODE(foo);
2432+
}
2433+
else {
2434+
res_stackref = 1;
2435+
}
2436+
/* End of uop copied from bytecodes for constant evaluation */
2437+
res = sym_new_const_steal(ctx, PyStackRef_AsPyObjectSteal(res_stackref));
2438+
stack_pointer[-1] = res;
2439+
break;
2440+
}
2441+
res = sym_new_known(ctx, foo);
2442+
stack_pointer[-1] = res;
2443+
break;
2444+
}
2445+
"""
2446+
self.run_cases_test(input, input2, output)
2447+
24012448
def test_replace_opocode_uop_reject_array_effects(self):
24022449
input = """
24032450
pure op(OP, (foo[2] -- res)) {

0 commit comments

Comments
 (0)