Skip to content

Commit 6fcd8d1

Browse files
committed
Rust: Refactor flow summary implementation
1 parent 047ea10 commit 6fcd8d1

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ private import codeql.rust.dataflow.FlowSummary
1111
private import codeql.rust.dataflow.Ssa
1212
private import Content
1313

14+
predicate encodeContentTupleField(TupleFieldContent c, string arg) {
15+
exists(Addressable a, int pos, string prefix |
16+
arg = prefix + "(" + pos + ")" and prefix = a.getCanonicalPath()
17+
|
18+
c.isStructField(a, pos) or c.isVariantField(a, pos)
19+
)
20+
}
21+
22+
predicate encodeContentStructField(StructFieldContent c, string arg) {
23+
exists(Addressable a, string field | arg = a.getCanonicalPath() + "::" + field |
24+
c.isStructField(a, field) or c.isVariantField(a, field)
25+
)
26+
}
27+
1428
module Input implements InputSig<Location, RustDataFlow> {
1529
private import codeql.rust.frameworks.stdlib.Stdlib
1630

@@ -58,24 +72,11 @@ module Input implements InputSig<Location, RustDataFlow> {
5872
exists(Content c | cs = TSingletonContentSet(c) |
5973
result = "Field" and
6074
(
61-
exists(Addressable a, int pos, string prefix |
62-
arg = prefix + "(" + pos + ")" and prefix = a.getCanonicalPath()
63-
|
64-
c.(TupleFieldContent).isStructField(a, pos)
65-
or
66-
c.(TupleFieldContent).isVariantField(a, pos)
67-
)
75+
encodeContentTupleField(c, arg)
6876
or
69-
exists(Addressable a, string field | arg = a.getCanonicalPath() + "::" + field |
70-
c.(StructFieldContent).isStructField(a, field)
71-
or
72-
c.(StructFieldContent).isVariantField(a, field)
73-
)
77+
encodeContentStructField(c, arg)
7478
or
75-
exists(int pos |
76-
c = TTuplePositionContent(pos) and
77-
arg = pos.toString()
78-
)
79+
exists(int pos | c = TTuplePositionContent(pos) and arg = pos.toString())
7980
)
8081
or
8182
result = "Reference" and

0 commit comments

Comments
 (0)