Skip to content

Commit 4c5f32b

Browse files
committed
Ruby: Cache exprNodeReturnedFrom
1 parent 45412fa commit 4c5f32b

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowDispatch.qll

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -463,18 +463,7 @@ predicate mayBenefitFromCallContext(DataFlowCall call, DataFlowCallable c) { non
463463
*/
464464
DataFlowCallable viableImplInCallContext(DataFlowCall call, DataFlowCall ctx) { none() }
465465

466-
/**
467-
* Holds if `e` is an `ExprNode` that may be returned by a call to `c`.
468-
*/
469-
predicate exprNodeReturnedFrom(DataFlow::ExprNode e, Callable c) {
470-
exists(ReturningNode r |
471-
nodeGetEnclosingCallable(r).asCallable() = c and
472-
(
473-
r.(ExplicitReturnNode).getReturningNode().getReturnedValueNode() = e.asExpr() or
474-
r.(ExprReturnNode) = e
475-
)
476-
)
477-
}
466+
predicate exprNodeReturnedFrom = exprNodeReturnedFromCached/2;
478467

479468
/** A parameter position. */
480469
class ParameterPosition extends TParameterPosition {

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,20 @@ private module Cached {
297297
TKnownArrayElementContent(int i) { i in [0 .. 10] } or
298298
TUnknownArrayElementContent() or
299299
TAnyArrayElementContent()
300+
301+
/**
302+
* Holds if `e` is an `ExprNode` that may be returned by a call to `c`.
303+
*/
304+
cached
305+
predicate exprNodeReturnedFromCached(ExprNode e, Callable c) {
306+
exists(ReturningNode r |
307+
nodeGetEnclosingCallable(r).asCallable() = c and
308+
(
309+
r.(ExplicitReturnNode).getReturningNode().getReturnedValueNode() = e.asExpr() or
310+
r.(ExprReturnNode) = e
311+
)
312+
)
313+
}
300314
}
301315

302316
class TArrayElementContent = TKnownArrayElementContent or TUnknownArrayElementContent;

0 commit comments

Comments
 (0)