From c940eb61e7bf1172b5b6addee663673c6ea9a6ac Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Fri, 12 Mar 2021 17:15:57 +0000 Subject: [PATCH 1/3] Cache TControlFlowNode --- ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll | 1 + 1 file changed, 1 insertion(+) diff --git a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll index bf1d1aef15e..018789c8ff8 100644 --- a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll +++ b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll @@ -61,6 +61,7 @@ private predicate isCond(Expr e) { * respectively, of the execution of the function and the loading of the file; * - Skip nodes that are semantic no-ops, but make CFG construction easier. */ +cached newtype TControlFlowNode = /** * A control-flow node that represents the evaluation of an expression. From ea7ecbaa55875c404d6aa5e3325324c19782eed4 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Mon, 15 Mar 2021 15:13:17 +0000 Subject: [PATCH 2/3] Add hint so optimizer doesn't choose bad join order --- ql/src/semmle/go/controlflow/IR.qll | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ql/src/semmle/go/controlflow/IR.qll b/ql/src/semmle/go/controlflow/IR.qll index 95270055d18..b0d8a8786d7 100644 --- a/ql/src/semmle/go/controlflow/IR.qll +++ b/ql/src/semmle/go/controlflow/IR.qll @@ -662,7 +662,7 @@ module IR { ) or exists(TypeAssertExpr tae | getBase() = evalExprInstruction(tae) | - result = tae.getType().(TupleType).getComponentType(i) + result = tae.getType().(TupleType).getComponentType(pragma[only_bind_into](i)) ) or exists(Type rangeType | rangeType = s.(RangeStmt).getDomain().getType().getUnderlyingType() | From f9c4e12c95befdaef34f13026900f99f7333ee4f Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Mon, 15 Mar 2021 15:13:40 +0000 Subject: [PATCH 3/3] Make `this.` explicit --- ql/src/semmle/go/controlflow/IR.qll | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ql/src/semmle/go/controlflow/IR.qll b/ql/src/semmle/go/controlflow/IR.qll index b0d8a8786d7..fb984f0041e 100644 --- a/ql/src/semmle/go/controlflow/IR.qll +++ b/ql/src/semmle/go/controlflow/IR.qll @@ -654,14 +654,14 @@ module IR { } /** Holds if this extracts the `idx`th value of the result of `base`. */ - predicate extractsElement(Instruction base, int idx) { base = getBase() and idx = i } + predicate extractsElement(Instruction base, int idx) { base = this.getBase() and idx = i } override Type getResultType() { - exists(CallExpr c | getBase() = evalExprInstruction(c) | + exists(CallExpr c | this.getBase() = evalExprInstruction(c) | result = c.getTarget().getResultType(i) ) or - exists(TypeAssertExpr tae | getBase() = evalExprInstruction(tae) | + exists(TypeAssertExpr tae | this.getBase() = evalExprInstruction(tae) | result = tae.getType().(TupleType).getComponentType(pragma[only_bind_into](i)) ) or