Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 52bf39b

Browse files
committed
C++: Use a 'fastTC' instead of '*' to improve performance.
1 parent a328565 commit 52bf39b

1 file changed

Lines changed: 38 additions & 21 deletions

File tree

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,35 +1328,35 @@ predicate localInstructionFlow(Instruction e1, Instruction e2) {
13281328

13291329
cached
13301330
private module ExprFlowCached {
1331-
/**
1332-
* Holds if `n1.asExpr()` doesn't have a result and `n1` flows to `n2` in a single
1333-
* dataflow step.
1334-
*/
1335-
private predicate localStepFromNonExpr(Node n1, Node n2) {
1336-
not exists(n1.asExpr()) and
1337-
localFlowStep(n1, n2)
1338-
}
1331+
/**
1332+
* Holds if `n1.asExpr()` doesn't have a result and `n1` flows to `n2` in a single
1333+
* dataflow step.
1334+
*/
1335+
private predicate localStepFromNonExpr(Node n1, Node n2) {
1336+
not exists(n1.asExpr()) and
1337+
localFlowStep(n1, n2)
1338+
}
13391339

1340-
/**
1341-
* Holds if `n1.asExpr()` doesn't have a result, `n2.asExpr() = e2` and
1342-
* `n2` is the first node reachable from `n1` such that `n2.asExpr()` exists.
1343-
*/
1344-
pragma[nomagic]
1345-
private predicate localStepsToExpr(Node n1, Node n2, Expr e2) {
1346-
localStepFromNonExpr*(n1, n2) and
1347-
e2 = n2.asExpr()
1348-
}
1340+
/**
1341+
* Holds if `n1.asExpr()` doesn't have a result, `n2.asExpr() = e2` and
1342+
* `n2` is the first node reachable from `n1` such that `n2.asExpr()` exists.
1343+
*/
1344+
pragma[nomagic]
1345+
private predicate localStepsToExpr(Node n1, Node n2, Expr e2) {
1346+
localStepFromNonExpr*(n1, n2) and
1347+
e2 = n2.asExpr()
1348+
}
13491349

13501350
/**
13511351
* Holds if `n1.asExpr() = e1` and `n2.asExpr() = e2` and `n2` is the first node
13521352
* reacahble from `n1` such that `n2.asExpr()` exists.
13531353
*/
13541354
private predicate localExprFlowSingleExprStep(Node n1, Expr e1, Node n2, Expr e2) {
13551355
exists(Node mid |
1356-
localFlowStep(n1, mid) and
1357-
localStepsToExpr(mid, n2, e2) and
1358-
e1 = n1.asExpr()
1359-
)
1356+
localFlowStep(n1, mid) and
1357+
localStepsToExpr(mid, n2, e2) and
1358+
e1 = n1.asExpr()
1359+
)
13601360
}
13611361

13621362
/**
@@ -1384,6 +1384,23 @@ private predicate localStepsToExpr(Node n1, Node n2, Expr e2) {
13841384
}
13851385

13861386
import ExprFlowCached
1387+
1388+
/**
1389+
* Holds if data can flow from `e1` to `e2` in one or more
1390+
* local (intra-procedural) steps.
1391+
*/
1392+
pragma[inline]
1393+
private predicate localExprFlowPlus(Expr e1, Expr e2) = fastTC(localExprFlowStep/2)(e1, e2)
1394+
1395+
/**
1396+
* Holds if data can flow from `e1` to `e2` in zero or more
1397+
* local (intra-procedural) steps.
1398+
*/
1399+
pragma[inline]
1400+
predicate localExprFlow(Expr e1, Expr e2) {
1401+
e1 = e2
1402+
or
1403+
localExprFlowPlus(e1, e2)
13871404
}
13881405

13891406
cached

0 commit comments

Comments
 (0)