GeezerVison is showing github.com — gh-136952: Fix C analyzer handling of static assertions by ShellWen · Pull Request #156969 · python/cpython
Conversation
ShellWen
commented
Sep 5, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
All commit authors signed the Contributor License Agreement.

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Reviewers
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
Milestone
No milestone
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.
|