-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rust: Fix variable access overlap #20727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3978004 to
5a24674
Compare
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.
Pull Request Overview
This PR fixes a bug in variable access resolution where a single variable access could incorrectly resolve to multiple variable declarations. The fix adjusts the scope resolution logic to prevent this overlap by ensuring that if a candidate is itself a VariableScope, it's not also treated as being enclosed by a scope.
Key Changes
- Modified scope resolution logic in
VariableImpl.qllto prevent double-counting of variable scopes - Added a new test case (
match_pattern15) demonstrating the fix - Added consistency query infrastructure to detect variable resolution issues
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/lib/codeql/rust/elements/internal/VariableImpl.qll | Fixed scope resolution to prevent a variable access from resolving to multiple variables |
| rust/ql/test/library-tests/variables/main.rs | Added test case match_pattern15 demonstrating the overlap issue |
| rust/ql/test/library-tests/variables/variables.expected | Updated test expectations with new variable declarations and accesses |
| rust/ql/test/library-tests/variables/Ssa.expected | Updated SSA analysis expectations following the fix |
| rust/ql/lib/codeql/rust/internal/VariableConsistency.qll | Added query predicate to detect multiple variable targets |
| rust/ql/consistency-queries/VariableConsistency.ql | Added consistency query to list variable inconsistencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
geoffw0
left a comment
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, quick question about the consistency query...
geoffw0
left a comment
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.
50412da to
6d64800
Compare
Fixes an issue where a variable access could resolve to multiple variables (see test code for example).
DCA looks good.