From 94447748954bc02298d494527d019556908762fe Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 16 Mar 2021 10:45:25 +0000 Subject: [PATCH] Add further hints that the range of possible addressed fields, and therefore the interesting selector expressions, are small --- .../go/controlflow/ControlFlowGraphImpl.qll | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll index 07a043bdce0..70685046777 100644 --- a/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll +++ b/ql/src/semmle/go/controlflow/ControlFlowGraphImpl.qll @@ -48,13 +48,13 @@ private predicate isCond(Expr e) { e = any(ParenExpr par | isCond(par)).getExpr() } -private class PromotedField extends Field { - PromotedField() { this = any(StructType t).getFieldOfEmbedded(_, _, _, _) } +private Type getSelectedStructType(PromotedFieldSelector e) { + pragma[only_bind_into](result) = e.getBase().getType().getBaseType*().getUnderlyingType() } -private predicate implicitFieldSelection(SelectorExpr e, int i, Field implicitField) { +private predicate implicitFieldSelection(PromotedFieldSelector e, int i, Field implicitField) { exists(StructType baseType, PromotedField child | - baseType = e.getBase().getType().getBaseType*().getUnderlyingType() and + baseType = getSelectedStructType(e) and ( e.refersTo(child) or @@ -65,6 +65,14 @@ private predicate implicitFieldSelection(SelectorExpr e, int i, Field implicitFi ) } +private class PromotedFieldSelector extends SelectorExpr { + PromotedFieldSelector() { this.refersTo(any(PromotedField f)) } +} + +private class PromotedField extends Field { + PromotedField() { this = any(StructType t).getFieldOfEmbedded(_, _, _, _) } +} + /** * A node in the intra-procedural control-flow graph of a Go function or file. *