From f6da34b546f3ec737695b2cdddebef02f6e96eb9 Mon Sep 17 00:00:00 2001 From: Max Schaefer Date: Fri, 31 Jul 2020 14:13:05 +0100 Subject: [PATCH] Speed up `unresolvedReference`. --- ql/src/semmle/go/dataflow/SSA.qll | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ql/src/semmle/go/dataflow/SSA.qll b/ql/src/semmle/go/dataflow/SSA.qll index 4f31c197ef2..519b281893a 100644 --- a/ql/src/semmle/go/dataflow/SSA.qll +++ b/ql/src/semmle/go/dataflow/SSA.qll @@ -42,14 +42,22 @@ class SsaSourceVariable extends LocalVariable { */ private predicate unresolvedReference(string name, FuncDef fn) { exists(Ident unresolved | - unresolved.getName() = name and - unresolved instanceof ReferenceExpr and + unresolvedIdentifier(unresolved, name) and not unresolved = any(SelectorExpr sel).getSelector() and - not unresolved.refersTo(_) and fn = unresolved.getEnclosingFunction() ) } +/** + * Holds if `id` is an unresolved identifier with the given `name`. + */ +pragma[noinline] +private predicate unresolvedIdentifier(Ident id, string name) { + id.getName() = name and + id instanceof ReferenceExpr and + not id.refersTo(_) +} + /** * An SSA variable. */