GH-122155: Fix cases generator to correctly compute 'peek' offset for error handling (GH-122158)

This commit is contained in:
Mark Shannon 2024-07-23 14:12:06 +01:00 committed by GitHub
parent 498cb6dff1
commit 624bda7638
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 68 additions and 6 deletions

View file

@ -1012,6 +1012,57 @@ class TestGeneratedCases(unittest.TestCase):
"""
self.run_cases_test(input, output)
def test_pop_on_error_peeks(self):
input = """
op(FIRST, (x, y -- a, b)) {
a = x;
b = y;
}
op(SECOND, (a, b -- a, b)) {
}
op(THIRD, (j, k --)) {
ERROR_IF(cond, error);
}
macro(TEST) = FIRST + SECOND + THIRD;
"""
output = """
TARGET(TEST) {
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(TEST);
_PyStackRef x;
_PyStackRef y;
_PyStackRef a;
_PyStackRef b;
_PyStackRef j;
_PyStackRef k;
// FIRST
y = stack_pointer[-1];
x = stack_pointer[-2];
{
a = x;
b = y;
}
// SECOND
{
}
// THIRD
k = b;
j = a;
{
if (cond) goto pop_2_error;
}
stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS());
DISPATCH();
}
"""
self.run_cases_test(input, output)
class TestGeneratedAbstractCases(unittest.TestCase):
def setUp(self) -> None: