Skip to content

Commit dd8f094

Browse files
committed
Rust: Refactor flow summary implementation
1 parent 789ac79 commit dd8f094

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.elements.internal.CallExprBaseImpl::Impl as CallExprBaseImpl
1630
private import codeql.rust.frameworks.stdlib.Stdlib
@@ -61,24 +75,11 @@ module Input implements InputSig<Location, RustDataFlow> {
6175
exists(Content c | cs = TSingletonContentSet(c) |
6276
result = "Field" and
6377
(
64-
exists(Addressable a, int pos, string prefix |
65-
arg = prefix + "(" + pos + ")" and prefix = a.getCanonicalPath()
66-
|
67-
c.(TupleFieldContent).isStructField(a, pos)
68-
or
69-
c.(TupleFieldContent).isVariantField(a, pos)
70-
)
78+
encodeContentTupleField(c, arg)
7179
or
72-
exists(Addressable a, string field | arg = a.getCanonicalPath() + "::" + field |
73-
c.(StructFieldContent).isStructField(a, field)
74-
or
75-
c.(StructFieldContent).isVariantField(a, field)
76-
)
80+
encodeContentStructField(c, arg)
7781
or
78-
exists(int pos |
79-
c = TTuplePositionContent(pos) and
80-
arg = pos.toString()
81-
)
82+
exists(int pos | c = TTuplePositionContent(pos) and arg = pos.toString())
8283
)
8384
or
8485
result = "Reference" and

0 commit comments

Comments
 (0)