Python: fix shared CFG exception-handler reachability - #22380
Open
yoff wants to merge 3 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
yoff
force-pushed
the
yoff-fix-shared-cfg-ssa-regressions
branch
from
August 19, 2026 15:42
94aa7e2 to
a93d631
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 20, 2026 06:55
a93d631 to
3dfc77e
Compare
yoff
changed the base branch from
yoff/python-shared-cfg-dataflow-flip
to
main
August 20, 2026 06:56
aschackmull
reviewed
Aug 20, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 860cd56d-31cf-49f4-a947-45e0d72447c6
This was referenced Aug 25, 2026
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
Fixes exception-handler reachability in the shared Python CFG introduced by #21921 and now present on
main. Testing the dataflow switch-over in #21925 surfaced the bug.Leaf expressions that may throw, including bare
yieldand plain imports, were not always connected to typed exception-handler entries. The fix uses the canonical shared-CFGinjectsmapping when starting exceptional completion, so these expressions reach the appropriate catch entry.Tests
Adds focused inline coverage for:
yieldreaching aGeneratorExithandler;ImportErrorhandler.DCA impact
The switch-over DCA in #38556 exposed effects of the missing exception edges in mypy, CPython, and youtube-dl. Restoring these edges recovers the affected catch reachability and downstream flow.
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