Skip to content

Commit d8c05b5

Browse files
authored
Merge pull request github#18290 from hvitved/rust/perf-fixes
Rust: Fix two bad joins
2 parents 132dbd7 + aabcc10 commit d8c05b5

File tree

1 file changed

+49
-47
lines changed

1 file changed

+49
-47
lines changed

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

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -957,8 +957,8 @@ module RustDataFlow implements InputSig<Location> {
957957
/** Holds if path `p` resolves to variant `v`. */
958958
private predicate pathResolveToVariantCanonicalPath(PathAstNode p, VariantCanonicalPath v) {
959959
exists(CrateOriginOption crate, string path, string name |
960-
resolveExtendedCanonicalPath(p, crate, path + "::" + name) and
961-
v = MkVariantCanonicalPath(crate, path, name)
960+
resolveExtendedCanonicalPath(p, pragma[only_bind_into](crate), path + "::" + name) and
961+
v = MkVariantCanonicalPath(pragma[only_bind_into](crate), path, name)
962962
)
963963
}
964964

@@ -1074,57 +1074,59 @@ module RustDataFlow implements InputSig<Location> {
10741074
)
10751075
}
10761076

1077+
pragma[nomagic]
1078+
private predicate storeContentStep(Node node1, Content c, Node node2) {
1079+
exists(CallExprCfgNode call, int pos |
1080+
tupleVariantConstruction(call.getCallExpr(),
1081+
c.(VariantPositionContent).getVariantCanonicalPath(pos)) and
1082+
node1.asExpr() = call.getArgument(pos) and
1083+
node2.asExpr() = call
1084+
)
1085+
or
1086+
exists(RecordExprCfgNode re, string field |
1087+
(
1088+
// Expression is for a struct-like enum variant.
1089+
recordVariantConstruction(re.getRecordExpr(),
1090+
c.(VariantFieldContent).getVariantCanonicalPath(field))
1091+
or
1092+
// Expression is for a struct.
1093+
structConstruction(re.getRecordExpr(), c.(StructFieldContent).getStructCanonicalPath(field))
1094+
) and
1095+
node1.asExpr() = re.getFieldExpr(field) and
1096+
node2.asExpr() = re
1097+
)
1098+
or
1099+
exists(TupleExprCfgNode tuple |
1100+
node1.asExpr() = tuple.getField(c.(TuplePositionContent).getPosition()) and
1101+
node2.asExpr() = tuple
1102+
)
1103+
or
1104+
c instanceof ArrayElementContent and
1105+
node1.asExpr() =
1106+
[
1107+
node2.asExpr().(ArrayRepeatExprCfgNode).getRepeatOperand(),
1108+
node2.asExpr().(ArrayListExprCfgNode).getAnExpr()
1109+
]
1110+
or
1111+
tupleAssignment(node1, node2.(PostUpdateNode).getPreUpdateNode(), c)
1112+
or
1113+
exists(AssignmentExprCfgNode assignment, IndexExprCfgNode index |
1114+
c instanceof ArrayElementContent and
1115+
assignment.getLhs() = index and
1116+
node1.asExpr() = assignment.getRhs() and
1117+
node2.(PostUpdateNode).getPreUpdateNode().asExpr() = index.getBase()
1118+
)
1119+
or
1120+
VariableCapture::storeStep(node1, c, node2)
1121+
}
1122+
10771123
/**
10781124
* Holds if data can flow from `node1` to `node2` via a store into `c`. Thus,
10791125
* `node2` references an object with a content `c.getAStoreContent()` that
10801126
* contains the value of `node1`.
10811127
*/
10821128
predicate storeStep(Node node1, ContentSet cs, Node node2) {
1083-
exists(Content c | c = cs.(SingletonContentSet).getContent() |
1084-
exists(CallExprCfgNode call, int pos |
1085-
tupleVariantConstruction(call.getCallExpr(),
1086-
c.(VariantPositionContent).getVariantCanonicalPath(pos)) and
1087-
node1.asExpr() = call.getArgument(pos) and
1088-
node2.asExpr() = call
1089-
)
1090-
or
1091-
exists(RecordExprCfgNode re, string field |
1092-
(
1093-
// Expression is for a struct-like enum variant.
1094-
recordVariantConstruction(re.getRecordExpr(),
1095-
c.(VariantFieldContent).getVariantCanonicalPath(field))
1096-
or
1097-
// Expression is for a struct.
1098-
structConstruction(re.getRecordExpr(),
1099-
c.(StructFieldContent).getStructCanonicalPath(field))
1100-
) and
1101-
node1.asExpr() = re.getFieldExpr(field) and
1102-
node2.asExpr() = re
1103-
)
1104-
or
1105-
exists(TupleExprCfgNode tuple |
1106-
node1.asExpr() = tuple.getField(c.(TuplePositionContent).getPosition()) and
1107-
node2.asExpr() = tuple
1108-
)
1109-
or
1110-
c instanceof ArrayElementContent and
1111-
node1.asExpr() =
1112-
[
1113-
node2.asExpr().(ArrayRepeatExprCfgNode).getRepeatOperand(),
1114-
node2.asExpr().(ArrayListExprCfgNode).getAnExpr()
1115-
]
1116-
or
1117-
tupleAssignment(node1, node2.(PostUpdateNode).getPreUpdateNode(), c)
1118-
or
1119-
exists(AssignmentExprCfgNode assignment, IndexExprCfgNode index |
1120-
c instanceof ArrayElementContent and
1121-
assignment.getLhs() = index and
1122-
node1.asExpr() = assignment.getRhs() and
1123-
node2.(PostUpdateNode).getPreUpdateNode().asExpr() = index.getBase()
1124-
)
1125-
or
1126-
VariableCapture::storeStep(node1, c, node2)
1127-
)
1129+
storeContentStep(node1, cs.(SingletonContentSet).getContent(), node2)
11281130
or
11291131
FlowSummaryImpl::Private::Steps::summaryStoreStep(node1.(Node::FlowSummaryNode).getSummaryNode(),
11301132
cs, node2.(Node::FlowSummaryNode).getSummaryNode())

0 commit comments

Comments
 (0)