Skip to content

new TestUopsOptimization test case failing an assert #117180

Closed
@lazorchakp

Description

@lazorchakp

Bug report

Bug description:

While writing test cases for #116168, I ran into a case that failed on main too. Here's the test as a diff. It's under test_opt.TestUopsOptimization:

diff --git a/Lib/test/test_capi/test_opt.py b/Lib/test/test_capi/test_opt.py
index b0859a382d..269753e4c1 100644
--- a/Lib/test/test_capi/test_opt.py
+++ b/Lib/test/test_capi/test_opt.py
@@ -955,6 +955,31 @@ def testfunc(n):
         _, ex = self._run_with_optimizer(testfunc, 16)
         self.assertIsNone(ex)

+    def test_many_nested(self):
+        # overflow the trace_stack
+        def dummy_a(x):
+            return x
+        def dummy_b(x):
+            return dummy_a(x)
+        def dummy_c(x):
+            return dummy_b(x)
+        def dummy_d(x):
+            return dummy_c(x)
+        def dummy_e(x):
+            return dummy_d(x)
+        def dummy_f(x):
+            return dummy_e(x)
+        def dummy_g(x):
+            return dummy_f(x)
+        def dummy_h(x):
+            return dummy_g(x)
+        def testfunc(n):
+            a = 0
+            for _ in range(n):
+                a += dummy_h(n)
+            return a
+
+        self._run_with_optimizer(testfunc, 32)

 if __name__ == "__main__":
     unittest.main()

I'm running this locally (source build of main 9967b568edd2e35b0415c14c7242f3ca2c0dc03d on an M1 mac).

Command:

./python.exe -m test test.test_capi.test_opt

Output:

Using random seed: 1780919823
Raised RLIMIT_NOFILE: 256 -> 1024
0:00:00 load avg: 2.88 Run 1 test sequentially
0:00:00 load avg: 2.88 [1/1] test.test_capi.test_opt
Assertion failed: ((this_instr + 2)->opcode == _PUSH_FRAME), function optimize_uops, file optimizer_cases.c.h, line 1600.
Fatal Python error: Aborted

Current thread 0x000000020140a100 (most recent call first):
  File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/test/test_capi/test_opt.py", line 979 in testfunc
  File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/test/test_capi/test_opt.py", line 588 in _run_with_optimizer
  File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/test/test_capi/test_opt.py", line 982 in test_many_nested
  File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/unittest/case.py", line 589 in _callTestMethod
....[truncated for brevity]....
  File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/runpy.py", line 88 in _run_code
  File "/Users/peterlazorchak/repos/oss-clones/forks/cpython/Lib/runpy.py", line 198 in _run_module_as_main

Extension modules: _testcapi, _testinternalcapi (total: 2)
zsh: abort      ./python.exe -m test test.test_capi.test_opt

This assertion is in the optimizer case for _INIT_CALL_PY_EXACT_ARGS. I haven't investigated any further beyond that.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions