Skip to content

Commit c087b0e

Browse files
committed
Add failing regression test for _TO_BOOL_STR
1 parent 3ae9101 commit c087b0e

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,38 @@ def crash_addition():
14371437

14381438
crash_addition()
14391439

1440+
def test_narrow_type_to_constant_str_empty(self):
1441+
def f(n):
1442+
trace = []
1443+
for i in range(n):
1444+
empty = ""
1445+
# Hopefully the optimizer can't guess what the value is.
1446+
# f is always "", but we can only prove that it's a string:
1447+
f = empty + empty
1448+
trace.append("A")
1449+
if not f: # Kept.
1450+
trace.append("B")
1451+
if not f: # Removed!
1452+
trace.append("C")
1453+
trace.append("D")
1454+
if f: # Removed!
1455+
trace.append("X")
1456+
trace.append("E")
1457+
trace.append("F")
1458+
if f: # Removed!
1459+
trace.append("X")
1460+
trace.append("G")
1461+
return trace
1462+
1463+
trace, ex = self._run_with_optimizer(f, TIER2_THRESHOLD)
1464+
self.assertEqual(trace, list("ABCDEFG") * TIER2_THRESHOLD)
1465+
self.assertIsNotNone(ex)
1466+
uops = get_opnames(ex)
1467+
# Only one guard remains:
1468+
self.assertEqual(uops.count("_GUARD_IS_FALSE_POP"), 1)
1469+
self.assertEqual(uops.count("_GUARD_IS_TRUE_POP"), 0)
1470+
# But all of the appends we care about are still there:
1471+
self.assertEqual(uops.count("_CALL_LIST_APPEND"), len("ABCDEFG"))
14401472

14411473
def global_identity(x):
14421474
return x

0 commit comments

Comments
 (0)