Python: fix shared CFG exception-handler reachability - #22380
Open
yoff wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes shared Python CFG/SSA regressions affecting exception-handler reachability and module-export phi uses.
Changes:
- Routes exceptional completion through canonical CFG nodes.
- Preserves synthetic normal-exit uses for generic SSA definitions.
- Adds regression tests for both fixes.
Show a summary per file
| File | Description |
|---|---|
python/ql/lib/semmle/python/controlflow/internal/AstNodeImpl.qll |
Uses canonical CFG-node mapping for exception flow. |
python/ql/lib/semmle/python/dataflow/new/internal/SsaImpl.qll |
Supports phi definitions when resolving uses. |
python/ql/test/library-tests/ControlFlow/shared-cfg-exceptions/test.py |
Adds yield and import exception cases. |
python/ql/test/library-tests/ControlFlow/shared-cfg-exceptions/ExceptionReachabilityTest.ql |
Checks typed-handler reachability. |
python/ql/test/library-tests/ControlFlow/shared-cfg-exceptions/ExceptionReachabilityTest.expected |
Records expected exception results. |
python/ql/test/library-tests/dataflow-new-ssa/test.py |
Adds conditional module-export coverage. |
python/ql/test/library-tests/dataflow-new-ssa/SsaTest.ql |
Checks synthetic exit uses for phi definitions. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 6/7 changed files
- Comments generated: 0
- Review effort level: Balanced
yoff
force-pushed
the
yoff-fix-shared-cfg-ssa-regressions
branch
from
August 19, 2026 11:24
9055769 to
94aa7e2
Compare
yoff
force-pushed
the
yoff/python-shared-cfg-dataflow-flip
branch
from
August 19, 2026 15:39
0394945 to
c69ba9a
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
yoff
force-pushed
the
yoff-fix-shared-cfg-ssa-regressions
branch
from
August 19, 2026 15:42
94aa7e2 to
a93d631
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This dependent PR fixes the shared-CFG exception-handler reachability regression introduced by #21925.
mayThrowexpressions such as bareyieldand plain imports reach typed catch entries.The SSA phi normal-exit/module-export fix previously included here has moved into #21923 and is now inherited through the restacked #21925 base; it is intentionally no longer duplicated in this PR.
Red/green structure
MISSINGexpectations for bare-yield and plain-import exceptional successors.isInwith canonicalinjectsmapping and flip those expectations green.The red commit passes with its bug annotations; replacing each
MISSINGannotation with the desired result reproduces the missing-result failure. The green commit passes without bug annotations.DCA impact
The exception fix restores catch reachability behind the removed
CatchingBaseExceptionrows in mypy and duplicated CPython results, as well as the youtube-dlUseOfExitstem. The AirflowApiException = BaseExceptionresult and other phi-dependent flows are supplied by the inherited #21923 fix.DCA #38556 evaluated pre-restack tree
121dd330738315cf6fc48629ab39d53667809c40. The reduced two-commit branch on the new #21925 base has the exact same Git tree, so the DCA correctness and performance conclusions remain directly applicable.Validation
codeql test run python/ql/test/library-tests/ControlFlow/shared-cfg-exceptionscodeql query format --check-only python/ql/test/library-tests/ControlFlow/shared-cfg-exceptions/ExceptionReachabilityTest.ql