Skip to content

SIGSEGV in test_isinstance and test_json with --enable-experimental-jit=yes and --with-lto=full #142543

Description

@ashm-dev

Bug report

Bug description:

I encountered segmentation faults (SIGSEGV, Exit code -11) while running the test suite on the main branch (3.15). The crashes occur during recursion tests in test_isinstance and test_json.

Build Environment:

  • Compiler: Clang 21
  • Flags: -march=native
  • Configuration:
    CC=clang-21 CXX=clang++-21 CFLAGS='-march=native' ./configure --enable-optimizations --enable-experimental-jit=yes --with-lto=full && make -j8

Reproduction:

./python -X dev -m test -j8 -uall

Crash 1: test_isinstance
Test: test_isinstance.py -> test_infinite_cycle_in_bases

Fatal Python error: Segmentation fault

Current thread 0x00007bac0e60f780 [python] (most recent call first):
  File "/home/shamil/oss/cpython/main/Lib/test/test_isinstance.py", line 338 in __bases__
  ...
  File "/home/shamil/oss/cpython/main/Lib/test/test_isinstance.py", line 340 in test_infinite_cycle_in_bases
  ...
Current thread's C stack trace (most recent call first):
  Binary file "/home/shamil/oss/cpython/main/python", at _Py_DumpStack+0x29
  ...
  Binary file "/home/shamil/oss/cpython/main/python", at _PyEval_EvalFrameDefault+0x1aa1a
  Binary file "/home/shamil/oss/cpython/main/python", at _PyFunction_Vectorcall+0xb83
  Binary file "/home/shamil/oss/cpython/main/python", at PyObject_CallOneArg+0x54
  ...
  <repeated calls>

Crash 2: test_json
Test: test_json/test_recursion.py -> test_endless_recursion

Fatal Python error: Segmentation fault

Current thread 0x00007e1fc251b780 [python] (most recent call first):
  File "/home/shamil/oss/cpython/main/Lib/test/test_json/test_recursion.py", line 109 in default
  File "/home/shamil/oss/cpython/main/Lib/json/encoder.py", line 263 in iterencode
  ...
Current thread's C stack trace (most recent call first):
  Binary file "/home/shamil/oss/cpython/main/python", at _Py_DumpStack+0x29
  ...
  Binary file "/home/shamil/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6afb
  Binary file "/home/shamil/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a7c
  <repeated calls>

Full tests log - tests.log

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Activity

  1. Fidget-Spinner commented on Dec 10, 2025

    @Fidget-Spinner
    Member

    Did you manage to narrow down where the SEGV is pointing to?

    Recursion shouldn't even trigger JIT compilation, only loops at the moment.

  2. ashm-dev commented on Dec 10, 2025

    @ashm-dev
    ContributorAuthor

    I'm still trying to understand

  3. ashm-dev commented on Dec 13, 2025

    @ashm-dev
    ContributorAuthor

    In this case, I don’t understand what’s causing the issue, since the segfaults do not reproduce in debug mode and/or with ASan enabled.

  4. Fidget-Spinner commented on Dec 13, 2025

    @Fidget-Spinner
    Member

    Does it reproduce with the tail call interpreter option with:

    CC=clang-21 CXX=clang++-21 CFLAGS='-march=native' ./configure --enable-optimizations --with-tail-call-interp --enable-experimental-jit=yes --with-lto=full && make -j8
    

    If it doesn't, then it's likely the C stack taking up too much space again on JIT builds.

  5. Fidget-Spinner commented on Dec 13, 2025

    @Fidget-Spinner
    Member

    Also can you provide the full stack trace please instead of a partial one? That will give much more info.

  6. ashm-dev commented on Dec 16, 2025

    @ashm-dev
    ContributorAuthor
    CC=clang-21 CXX=clang++-21 CFLAGS='-march=native' ./configure --enable-optimizations --enable-experimental-jit=yes --with-lto=full

    test_isinstance

    $ ./python -X dev -m test test_isinstance -j8 -uall
    Using random seed: 211998123
    0:00:00 load avg: 1.41 Run 1 test in parallel using 1 worker process
    0:00:00 load avg: 1.41 [1/1/1] test_isinstance worker non-zero exit code (Exit code -11 (SIGSEGV))
    Fatal Python error: Segmentation fault
    
    Current thread 0x00007f62cca3d780 [python] (most recent call first):
      File "/home/boss/projects/oss/cpython/main/Lib/test/test_isinstance.py", line 338 in __bases__
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/case.py", line 245 in handle
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/case.py", line 811 in assertRaises
      File "/home/boss/projects/oss/cpython/main/Lib/test/test_isinstance.py", line 340 in test_infinite_cycle_in_bases
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/case.py", line 613 in _callTestMethod
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/case.py", line 667 in run
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/case.py", line 723 in __call__
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 122 in run
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 84 in __call__
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 122 in run
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 84 in __call__
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/testresult.py", line 148 in run
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 84 in _run_suite
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 42 in run_unittest
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 162 in test_func
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 118 in regrtest_runner
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 165 in _load_run_test
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 210 in _runtest_env_changed_exc
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 319 in _runtest
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 348 in run_single_test
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/worker.py", line 99 in worker_process
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/worker.py", line 134 in main
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/worker.py", line 138 in <module>
      File "<frozen runpy>", line 87 in _run_code
      File "<frozen runpy>", line 196 in _run_module_as_main
    
    Current thread's C stack trace (most recent call first):
      Binary file "/home/boss/projects/oss/cpython/main/python", at _Py_DumpStack+0x3a [0x55aea94cdbba]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0x16bb38 [0x55aea94dbb38]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0x16ba77 [0x55aea94dba77]
      Binary file "/usr/lib/libc.so.6", at +0x3e4d0 [0x7f62cc83e4d0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0x1ef289 [0x55aea955f289]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0x3a4bf6 [0x55aea9714bf6]
      Binary file "/home/boss/projects/oss/cpython/main/python", at _PyEval_EvalFrameDefault+0x1c380 [0x55aea95b6de0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at _PyFunction_Vectorcall+0xc0e [0x55aea952b4fe]
      Binary file "/home/boss/projects/oss/cpython/main/python", at PyObject_CallOneArg+0x61 [0x55aea9425681]
      Binary file "/home/boss/projects/oss/cpython/main/python", at PyObject_GetOptionalAttr+0x1d8f [0x55aea9449e7f]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0d05 [0x55aea9420d05]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0c0b [0x55aea9420c0b]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0xb0cc0 [0x55aea9420cc0]
      <truncated rest of calls>
    
    Extension modules: math.integer, _testinternalcapi (total: 2)
    
    == Tests result: FAILURE ==
    
    1 test failed:
        test_isinstance
    
    Total duration: 276 ms
    Total tests: run=0
    Total test files: run=1/1 failed=1
    Result: FAILURE
    

    test_json

    $ ./python -X dev -m test test_json -j8 -uall
    Using random seed: 2949834397
    0:00:00 load avg: 0.58 Run 1 test in parallel using 1 worker process
    0:00:00 load avg: 0.58 [1/1/1] test_json worker non-zero exit code (Exit code -11 (SIGSEGV))
    Fatal Python error: Segmentation fault
    
    Current thread 0x00007f763b0cb780 [python] (most recent call first):
      File "/home/boss/projects/oss/cpython/main/Lib/test/test_json/test_recursion.py", line 109 in default
      File "/home/boss/projects/oss/cpython/main/Lib/json/encoder.py", line 263 in iterencode
      File "/home/boss/projects/oss/cpython/main/Lib/json/encoder.py", line 202 in encode
      File "/home/boss/projects/oss/cpython/main/Lib/test/test_json/test_recursion.py", line 113 in test_endless_recursion
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/case.py", line 613 in _callTestMethod
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/case.py", line 667 in run
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/case.py", line 723 in __call__
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 122 in run
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 84 in __call__
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 122 in run
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 84 in __call__
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 122 in run
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 84 in __call__
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 122 in run
      File "/home/boss/projects/oss/cpython/main/Lib/unittest/suite.py", line 84 in __call__
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/testresult.py", line 148 in run
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 84 in _run_suite
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 42 in run_unittest
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 162 in test_func
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 118 in regrtest_runner
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 165 in _load_run_test
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 210 in _runtest_env_changed_exc
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 319 in _runtest
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/single.py", line 348 in run_single_test
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/worker.py", line 99 in worker_process
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/worker.py", line 134 in main
      File "/home/boss/projects/oss/cpython/main/Lib/test/libregrtest/worker.py", line 138 in <module>
      File "<frozen runpy>", line 87 in _run_code
      File "<frozen runpy>", line 196 in _run_module_as_main
    
    Current thread's C stack trace (most recent call first):
      Binary file "/home/boss/projects/oss/cpython/main/python", at _Py_DumpStack+0x3a [0x55fcbcb0ebba]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0x16bb38 [0x55fcbcb1cb38]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0x16ba77 [0x55fcbcb1ca77]
      Binary file "/usr/lib/libc.so.6", at +0x3e4d0 [0x7f763ae3e4d0]
      Binary file "/home/boss/projects/oss/cpython/main/python", at _PyEval_EvalFrameDefault+0x118db [0x55fcbcbed33b]
      Binary file "/home/boss/projects/oss/cpython/main/python", at _PyFunction_Vectorcall+0xc0e [0x55fcbcb6c4fe]
      Binary file "/home/boss/projects/oss/cpython/main/python", at +0x1be2c5 [0x55fcbcb6f2c5]
      Binary file "/home/boss/projects/oss/cpython/main/python", at PyObject_CallOneArg+0x61 [0x55fcbca66681]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b06 [0x7f763b029b06]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6b3c [0x7f763b029b3c]
      Binary file "/home/boss/projects/oss/cpython/main/build/lib.linux-x86_64-3.15/_json.cpython-315-x86_64-linux-gnu.so", at +0x6a6e [0x7f763b029a6e]
      <truncated rest of calls>
    
    Extension modules: math.integer, _testinternalcapi (total: 2)
    
    == Tests result: FAILURE ==
    
    1 test failed:
        test_json
    
    Total duration: 365 ms
    Total tests: run=0
    Total test files: run=1/1 failed=1
    Result: FAILURE
    

    CC=clang-21 CXX=clang++-21 CFLAGS='-march=native' ./configure --enable-optimizations --with-tail-call-interp --enable-experimental-jit=yes --with-lto=full

    test_isinstanse

    $ ./python -X dev -m test test_isinstance -j8 -uall
    Using random seed: 2606059884
    0:00:00 load avg: 1.64 Run 1 test in parallel using 1 worker process
    0:00:02 load avg: 1.59 [1/1] test_isinstance passed
    
    == Tests result: SUCCESS ==
    
    1 test OK.
    
    Total duration: 2.5 sec
    Total tests: run=23
    Total test files: run=1/1
    Result: SUCCESS
    

    test_json

    $ ./python -X dev -m test test_json -j8 -uall
    Using random seed: 2493830420
    0:00:00 load avg: 1.92 Run 1 test in parallel using 1 worker process
    0:00:03 load avg: 1.85 [1/1] test_json passed
    
    == Tests result: SUCCESS ==
    
    1 test OK.
    
    Total duration: 3.6 sec
    Total tests: run=213 skipped=1
    Total test files: run=1/1
    Result: SUCCESS
    

  7. Fidget-Spinner commented on Dec 16, 2025

    @Fidget-Spinner
    Member

    Ok so that pretty much confirms this is a stack overflow issue. Thank you.

  8. Fidget-Spinner commented on Dec 16, 2025

    @Fidget-Spinner
    Member

    I think this is similar to #137731

  9. added a commit that references this issue on Dec 17, 2025
  10. Fidget-Spinner commented on Dec 17, 2025

    @Fidget-Spinner
    Member

    @ashm-dev thanks for the bug report. Can you please try main now again? I checked on my machine that it should've fixed your issues.

  11. ashm-dev commented on Dec 17, 2025

    @ashm-dev
    ContributorAuthor

    Yes, it's all right now.

    boss@oops-lab ~/projects/oss/cpython/main (main)
    $ ./python -c 'import sys; print(sys.version)'
    3.15.0a3+ (heads/main:89729f2ef7, Dec 17 2025, 03:23:07) [Clang 21.1.6 ]
    boss@oops-lab ~/projects/oss/cpython/main (main)
    $ ./python -X dev -m test test_isinstance test_json -j8 -uall
    Using random seed: 1474902128
    0:00:00 load avg: 0.14 Run 2 tests in parallel using 2 worker processes
    0:00:02 load avg: 0.14 [1/2] test_isinstance passed
    0:00:03 load avg: 0.21 [2/2] test_json passed
    
    == Tests result: SUCCESS ==
    
    All 2 tests OK.
    
    Total duration: 3.7 sec
    Total tests: run=236 skipped=1
    Total test files: run=2/2
    Result: SUCCESS
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions