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-136952: Fix C analyzer handling of static assertions by ShellWen · Pull Request #156969 · python/cpython

Conversation

@ShellWen

@ShellWen ShellWen commented Sep 5, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown

Fixes #136952.

The C analyzer preprocesses source files in C99 mode. With the headers used
in the reported configuration, static assertions expand into compatibility
declarations that the parser cannot handle. This causes analysis of
Python/gc_free_threading.c to fail when configured with --disable-gil.

This change:

  • Uses C11 preprocessing to avoid the compatibility expansion.
  • Handles _Static_assert and static_assert declarations at file scope
    and inside structs and unions, reusing the existing parenthesis-matching
    logic.
  • Adds focused regression tests to verify that declarations following
    static assertions are still discovered.

The assertions in CPython's C code remain unchanged.

Testing

Validated with a locally built CPython 3.16 free-threading interpreter:

  • Reproduced the reported analysis failure before the fix.
  • Ran python -m test test_tools: 80 tests run, 1 skipped, successful.
  • Ran check-c-globals.py on Python/gc.c,
    Python/gc_free_threading.c, and Objects/listobject.c:
    0 failures.
  • Temporarily restored C99 preprocessing in memory and confirmed that
    the preprocessing regression test fails.
  • git diff --check passes.

The full CPython test suite was not run.

AI assistance

GPT-6 Astra via OpenCode v2 assisted with investigating the issue,
implementing the changes, and preparing the tests and this PR description.

  • Issue: The C analyzer seems to fail when --disable-gil is set #136952

Sorry, something went wrong.

Uh oh!

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

All reactions
@ShellWen
ShellWen requested a review from ericsnowcurrently as a code owner September 5, 2026 06:43
Copilot AI lite review requested due to automatic review settings September 5, 2026 06:43
@python-cla-bot

python-cla-bot Bot commented Sep 5, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot mentioned this pull request Sep 5, 2026
The C analyzer seems to fail when --disable-gil is set #136952
Open
@bedevere-app bedevere-app Bot added the awaiting review label Sep 5, 2026
Copilot started reviewing on behalf of ShellWen September 5, 2026 06:44
View session
Copilot AI reviewed Sep 5, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

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.

🟢 Approval recommended

The change is tightly scoped to the tooling, directly addresses the reported failure mode, and includes targeted regression tests for both parsing and preprocessing behavior.

Pull request overview

This PR fixes the CPython C analyzer failing to parse free-threading builds where static assertions expand into declarations the parser can’t handle, by switching preprocessing to C11 and teaching the parser to skip _Static_assert / static_assert declarations while still discovering subsequent declarations.

Changes:

  • Preprocess analyzed C sources in C11 mode to avoid C99-era static_assert compatibility expansions.
  • Add parser support to skip _Static_assert / static_assert at file scope and inside struct/union bodies using existing parenthesis-matching logic.
  • Add regression tests covering global-scope, struct-scope, and real-preprocessor scenarios to ensure declarations after static assertions are still found.
File summaries
File Description
Tools/c-analyzer/c_parser/preprocessor/gcc.py Switch preprocessor standard from C99 to C11 to avoid problematic static-assert expansions.
Tools/c-analyzer/c_parser/parser/_common.py Add skip_static_assert() helper that consumes static-assert declarations (including multi-line) and preserves trailing declarations.
Tools/c-analyzer/c_parser/parser/_global.py Apply skip_static_assert() in global parsing so static assertions don’t block discovery of globals.
Tools/c-analyzer/c_parser/parser/_compound_decl_body.py Apply skip_static_assert() in struct/union member parsing so static assertions don’t block field discovery.
Lib/test/test_tools/test_c_analyzer.py Add focused regression tests for parser behavior and GCC preprocessing output.
Misc/NEWS.d/next/Tools-Demos/2026-09-05-00-00-00.gh-issue-136952.Jx7mQp.rst Document the tool fix in NEWS.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sorry, something went wrong.

Uh oh!

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

All reactions
ShellWen added 2 commits September 6, 2026 16:00
@ShellWen
pythongh-136952: Fix C analyzer handling of static assertions
f1a6659
@ShellWen
pythongh-136952: Handle analyzer alignment and GCC test portability
8110334
@ShellWen
ShellWen force-pushed the gh-136952-c-analyzer-static-assert branch from b0b0ae5 to 8110334 Compare September 6, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

The C analyzer seems to fail when --disable-gil is set

Uh oh!

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

2 participants

@ShellWen
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.