Skip to content

Commit dbef36c

Browse files
committed
Python: Prevent bad TC and add a bit of caching
Using `simpleLocalFlowStep+` with the first argument specialised to `CfgNode` was causing the compiler to turn this into a very slowly converging manual TC computation. Instead, we use `simpleLocalFlowStep*` (which is fast) and then join that with a single step from any `CfgNode`. This should amount to the same thing. I also noticed that the charpred for `LocalSourceNode` was getting recomputed a lot, so this is now cached. (The recomputation was especially bad since it relied on `simpleLocalFlowStep+`, but anyway it's a good idea not to recompute this.)
1 parent 0ae8b69 commit dbef36c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

python/ql/src/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,22 @@ class BarrierGuard extends GuardNode {
467467
}
468468
}
469469

470+
private predicate comes_from_cfgnode(Node node) {
471+
exists(Node second |
472+
simpleLocalFlowStep(any(CfgNode c), second) and
473+
simpleLocalFlowStep*(second, node)
474+
)
475+
}
476+
470477
/**
471478
* A data flow node that is a source of local flow. This includes things like
472479
* - Expressions
473480
* - Function parameters
474481
*/
475482
class LocalSourceNode extends Node {
483+
cached
476484
LocalSourceNode() {
477-
not simpleLocalFlowStep+(any(CfgNode n), this) and
485+
not comes_from_cfgnode(this) and
478486
not this instanceof ModuleVariableNode
479487
or
480488
this = any(ModuleVariableNode mvn).getARead()

0 commit comments

Comments
 (0)