Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,12 @@ module Impl {
VariableAccessCand cand, VariableScope scope, string name, int nestLevel, int ord
) {
name = cand.getName() and
scope = [cand.(VariableScope), getEnclosingScope(cand)] and
(
scope = cand
or
not cand instanceof VariableScope and
scope = getEnclosingScope(cand)
) and
ord = getPreOrderNumbering(scope, cand) and
nestLevel = 0
or
Expand Down
11 changes: 11 additions & 0 deletions rust/ql/lib/codeql/rust/internal/AstConsistency.qll
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ query predicate multiplePositions(Element parent, int pos1, int pos2, string acc
pos1 != pos2
}

/**
* Holds if `va` is a variable access that refers to multiple variables.
*/
query predicate multipleVariableTargets(VariableAccess va, Variable v1) {
va = v1.getAnAccess() and
strictcount(va.getVariable()) > 1
}

/**
* Gets counts of abstract syntax tree inconsistencies of each type.
*/
Expand All @@ -98,4 +106,7 @@ int getAstInconsistencyCounts(string type) {
or
type = "Multiple positions" and
result = count(Element e | multiplePositions(_, _, _, _, e) | e)
or
type = "Multiple variable targets" and
result = count(VariableAccess va | multipleVariableTargets(va, _) | va)
}
2,040 changes: 1,031 additions & 1,009 deletions rust/ql/test/library-tests/variables/Cfg.expected

Large diffs are not rendered by default.

783 changes: 395 additions & 388 deletions rust/ql/test/library-tests/variables/Ssa.expected

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions rust/ql/test/library-tests/variables/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,15 @@ fn match_pattern14() {
}
}

fn match_pattern15() {
let x = Some(0); // x1
match x { // $ read_access=x1
Some(x) // x2
=> x, // $ read_access=x2
_ => 0
};
}

fn param_pattern1(
a8: &str, // a8
(
Expand Down Expand Up @@ -757,6 +766,7 @@ fn main() {
match_pattern12();
match_pattern13();
match_pattern14();
match_pattern15();
param_pattern1("a", ("b", "c"));
param_pattern2(Either::Left(45));
destruct_assignment();
Expand Down
Loading