From 22a3fccf794ab4a9e9991f257df5cc4a117c019d Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 15 Mar 2021 11:59:36 +0000 Subject: [PATCH] Use type to hint that constraining to embedded fields is a good first step This improves the join order for `implicitFieldSelection` --- ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll index fd4657d8741..07a043bdce0 100644 --- a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll +++ b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll @@ -48,11 +48,15 @@ private predicate isCond(Expr e) { e = any(ParenExpr par | isCond(par)).getExpr() } +private class PromotedField extends Field { + PromotedField() { this = any(StructType t).getFieldOfEmbedded(_, _, _, _) } +} + private predicate implicitFieldSelection(SelectorExpr e, int i, Field implicitField) { - exists(StructType baseType, Field child | + exists(StructType baseType, PromotedField child | baseType = e.getBase().getType().getBaseType*().getUnderlyingType() and ( - e.getSelector() = child.getAReference() + e.refersTo(child) or implicitFieldSelection(e, i + 1, child) )