From 2482519cd3c9b9bd6a17216bed2f86d1a98f6450 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Fri, 26 Apr 2024 13:09:59 +0100 Subject: [PATCH] DataFlow: Cached second level scope. --- shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll | 5 +++-- .../dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll b/shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll index de9f718b347c..10c7efdf045f 100644 --- a/shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll +++ b/shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll @@ -1119,9 +1119,10 @@ module MakeImpl Lang> { pragma[nomagic] private SndLevelScopeOption getScope(RetNodeEx ret) { - result = SndLevelScopeOption::some(getSecondLevelScope(ret.asNode())) + result = SndLevelScopeOption::some(getSecondLevelScopeCached(ret.asNode())) or - result instanceof SndLevelScopeOption::None and not exists(getSecondLevelScope(ret.asNode())) + result instanceof SndLevelScopeOption::None and + not exists(getSecondLevelScopeCached(ret.asNode())) } pragma[nomagic] diff --git a/shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll b/shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll index 38c3bba3254f..9524ca9d9aba 100644 --- a/shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll +++ b/shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll @@ -616,6 +616,9 @@ module MakeImplCommon Lang> { cached predicate forceCachingInSameStage() { any() } + cached + DataFlowSecondLevelScope getSecondLevelScopeCached(Node n) { result = getSecondLevelScope(n) } + cached predicate nodeEnclosingCallable(Node n, DataFlowCallable c) { c = nodeGetEnclosingCallable(n) }