GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-148284: Block inlining of gigantic functions in ceval.c for clang 22 by Fidget-Spinner · Pull Request #148334 · python/cpython

Conversation

@Fidget-Spinner

@Fidget-Spinner Fidget-Spinner commented Apr 10, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

It seems that on clang-22, the inliner is too aggressive on _PyEval_EvalFrameDefault when on computed goto interpreter. Together with some strange interaction with the stackref buffer, the function requires 40kB of stack space (!!!) versus the usual 1-2kB normally used.

This sets the inline limit to functions of max 512B stack space (1/4th of normal) allowed to be inlined in ceval.c. I checked the dissasembly and the new function uses about 2kB of stack.

  • Issue: python -m test -v test_call segfault with clang 22.1.3 build #148284

📚 Documentation preview 📚: https://cpython-previews--148334.org.readthedocs.build/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Fidget-Spinner and others added 5 commits April 10, 2026 20:29
@Fidget-Spinner
Block inlining of gigantic functions
1a85b01
@blurb-it @Fidget-Spinner
📜🤖 Added by blurb_it.
291f142
@Fidget-Spinner
remove unused function
4b79670
@Fidget-Spinner @vstinner
Address Victor review
a95c401
Co-Authored-By: Victor Stinner <[email protected]>
@Fidget-Spinner
Delete 2026-04-10-09-21-40.gh-issue-148284.6xMH49.rst
91352a9
@Fidget-Spinner
Fidget-Spinner requested review from AA-Turner, corona10, emmatyping and erlend-aasland as code owners April 10, 2026 14:16
@bedevere-app bedevere-app Bot added the awaiting core review label Apr 10, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 10, 2026
python -m test -v test_call segfault with clang 22.1.3 build #148284
Closed
@blurb-it
📜🤖 Added by blurb_it.
0ddb3ec
@Fidget-Spinner Fidget-Spinner mentioned this pull request Apr 10, 2026
[3.14] gh-148284: Block inlining of gigantic functions in ceval.c for clang 22 #148326
Closed
@Fidget-Spinner

Fidget-Spinner commented Apr 10, 2026

Copy link
Copy Markdown
Member Author

Tested with

RANLIB="/usr/bin/llvm-ranlib-22" LLVM_PROFDATA="/usr/bin/llvm-profdata-22" LLVM_AR="/usr/bin/llvm-ar-22" CC="clang-22" CXX="clang++-22" LDFLAGS="-fuse-ld=lld-22" ./configure --enable-optimizations --with-lto --enable-shared  && make clean && make -j18

test_call fails on main, passes on this branch. Please help me check if you can. Thank you!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner

Fidget-Spinner commented Apr 10, 2026

Copy link
Copy Markdown
Member Author

So it seems whether the original bug reproduces on main or not is nondeterministic 😨 . However, I still believe this fix is right.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner
Fidget-Spinner requested a review from vstinner April 10, 2026 14:50
@vstinner

vstinner commented Apr 10, 2026

Copy link
Copy Markdown
Member

So it seems whether the original bug reproduces on main or not is nondeterministic 😨 . However, I still believe this fix is right.

I built the Python main branch (without the fix) 3 times in a row from scratch (git clean -fdx): the two first builds didn't reproduce the issue (stack memory per call: 1.2 kB), the 3rd build reproduced the issue (stack memory per call: 33.1 kB).


I built the Python main branch on Fedora Rawhide (clang 22.1.3) with:

./configure --enable-optimizations --with-lto --enable-shared CC=clang LD=clang
time make -j14

On the two first builds, LD_LIBRARY_PATH=$PWD ./python -m test -v test_call test passed successfully (expected: test fails). On the 3rd build, the test failed.

Script:

import _testcapi
import functools

def py_call():
    return _testcapi.stack_pointer()

def call():
    return py_call()

start = _testcapi.stack_pointer()
call = functools.partial(call)
top = call()
diff = start - top
print("stack memory per call: %.1f kB" % (diff / 1024))

Output on the first two builds:

stack memory per call: 1.2 kB

Output on the third build:

stack memory per call: 33.1 kB

Note: I installed clang and its dependencies using sudo dnf install clang llvm-ar compiler-rt.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner reviewed Apr 10, 2026
View reviewed changes
Comment thread Doc/using/configure.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 10, 2026

Copy link
Copy Markdown
Member

To get a more reproducible output, I tried using ./python -I -c pass as the "profile task".

Using ./configure --enable-optimizations --with-lto --enable-shared CC=clang LD=clang PROFILE_TASK='-I -c pass', I get a smaller stack memory usage: stack memory per call: 0.8 kB.

I built the Python main branch 3 times with these options and I got the same result each time: test_call pass and stack memory per call: 0.8 kB. I don't reproduce the issue with these options.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 10, 2026

Copy link
Copy Markdown
Member

Ok, now testing the fix. I built Python with the fix 5 times in a row and test_call succeeded each time. The fix is reliable!

  • Build 1: success (stack memory per call: 1.2 kB)
  • Build 2: success (stack memory per call: 1.2 kB)
  • Build 3: success (stack memory per call: 1.2 kB)
  • Build 4: success (stack memory per call: 1.2 kB)
  • Build 5: success (stack memory per call: 1.2 kB)

Commands:

./configure --enable-optimizations --with-lto --enable-shared CC=clang LD=clang
time make -j14
LD_LIBRARY_PATH=$PWD ./python -m test -v test_call

Result: test_call pass successfully and my script outputs stack memory per call: 1.2 kB.

Moreover, the C flags are set as expected in Makefile:

$ grep ^CFLAGS_CEVAL Makefile
CFLAGS_CEVAL= -finline-max-stacksize=512
Fidget-Spinner reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner approved these changes Apr 10, 2026
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The fix works as expected according to my manual tests (see above).

In general, I'm not fan of using a specific compiler option depending on the compiler veresion. In this case, I'm fine with it, it's a good trade-off.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Fidget-Spinner reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Apr 10, 2026
@Fidget-Spinner
Fidget-Spinner merged commit e007631 into python:main Apr 10, 2026
53 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 10, 2026
@Fidget-Spinner
Fidget-Spinner deleted the block_inlining_3.15 branch April 10, 2026 16:52
@Fidget-Spinner Fidget-Spinner added the needs backport to 3.14 bugs and security fixes label Apr 10, 2026
@Fidget-Spinner

Fidget-Spinner commented Apr 10, 2026

Copy link
Copy Markdown
Member Author

Thanks @vstinner for the very thorough testing and review :).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Apr 10, 2026

Copy link
Copy Markdown

Thanks @Fidget-Spinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 10, 2026
@Fidget-Spinner @vstinner @miss-islington
pythongh-148284: Block inlining of gigantic functions in ceval.c for …
3b60a68
…clang 22 (pythonGH-148334)

(cherry picked from commit e007631)

Co-authored-by: Ken Jin <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@bedevere-app

bedevere-app Bot commented Apr 10, 2026

Copy link
Copy Markdown

GH-148349 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Apr 10, 2026
Fidget-Spinner added a commit that referenced this pull request Apr 10, 2026
@miss-islington @Fidget-Spinner @vstinner
[3.14] gh-148284: Block inlining of gigantic functions in ceval.c for…
288cbac
… clang 22 (GH-148334) (GH-148349)

gh-148284: Block inlining of gigantic functions in ceval.c for clang 22 (GH-148334)
(cherry picked from commit e007631)

Co-authored-by: Ken Jin <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
@vstinner

vstinner commented Apr 10, 2026

Copy link
Copy Markdown
Member

Since the bug occurs randomly on clang 22 (coarse estimation 1/3 builds affected), I double checked clang 21.

I built the Python main branch (without the fix) multiple times on Fedora Stable (clang 21.1.8): I failed to reproduce the issue. I confirm that the issue is specific to clang 22.

  • Build 1: success (stack memory per call: 1.2 kB)
  • Build 2: success (stack memory per call: 1.2 kB)
  • Build 3: success (stack memory per call: 1.2 kB)
  • Build 4: success (stack memory per call: 1.2 kB)
  • Build 5: success (stack memory per call: 1.2 kB)

By the way, we do have Fedora Rawhide Clang buildbots (AArch64, AMD64, PPC64LE, s390x) with Clang 22.1.3, but they don't test the LTO+PGO case:

  • "Clang" flavor tests ./configure CC=clang LD=clang --with-pydebug (clang -Og)
  • "Clang Installed" flavor tests ./configure CC=clang LD=clang (clang -O3)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Fidget-Spinner

Fidget-Spinner commented Apr 10, 2026

Copy link
Copy Markdown
Member Author

@vstinner if you want to test. 3.14 reliably crashes every single time I build with clang-22 before my patch was applied (ie at commit 429c1d3) You can try it out with clang-21 to see if it crashes.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 10, 2026

Copy link
Copy Markdown
Member

@vstinner if you want to test. 3.14 reliably crashes every single time I build with clang-22 before my patch was applied (ie at commit 429c1d3) You can try it out with clang-21 to see if it crashes.

I built the commit 429c1d3 wih clang 21 (Fedora Stable): I failed to reproduce the issue, test_call pass successfully and my script gives stack memory per call: 2.3 kB.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@Fidget-Spinner @vstinner @ljfp
pythongh-148284: Block inlining of gigantic functions in ceval.c for …
35a1785
…clang 22 (pythonGH-148334)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@emmatyping emmatyping Awaiting requested review from emmatyping emmatyping is a code owner
@corona10 corona10 Awaiting requested review from corona10 corona10 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Fidget-Spinner @vstinner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.