@@ -9,10 +9,13 @@ private import DataFlowPrivate
99private import FlowSummaryImpl as FlowSummaryImpl
1010private import semmle.go.dataflow.ExternalFlow
1111
12+ private module SsaFlow = SsaImpl:: DataFlowIntegration;
13+
1214cached
1315private newtype TNode =
1416 MkInstructionNode ( IR:: Instruction insn ) or
1517 MkSsaNode ( SsaDefinition ssa ) or
18+ MkSsaSynthReadNode ( SsaFlow:: SsaSynthReadNode ssa ) or
1619 MkGlobalFunctionNode ( Function f ) or
1720 MkImplicitVarargsSlice ( IR:: EvalInstruction ins ) {
1821 // We only use CallExprs with an EvalInstruction to guarantee reachability.
@@ -26,6 +29,55 @@ private newtype TNode =
2629module Private {
2730 private import DataFlowDispatch
2831
32+ /** A synthetic SSA read at a control-flow merge. */
33+ class SsaSynthReadNode extends Node , MkSsaSynthReadNode {
34+ private SsaFlow:: SsaSynthReadNode ssa ;
35+
36+ SsaSynthReadNode ( ) { this = MkSsaSynthReadNode ( ssa ) }
37+
38+ SsaFlow:: SsaSynthReadNode getSsaNode ( ) { result = ssa }
39+
40+ override ControlFlow:: Root getRoot ( ) { result = ssa .getBasicBlock ( ) .getScope ( ) }
41+
42+ override BasicBlock getBasicBlock ( ) { result = ssa .getBasicBlock ( ) }
43+
44+ override Type getType ( ) { result = ssa .getSourceVariable ( ) .getType ( ) }
45+
46+ override string getNodeKind ( ) { result = "SSA synthetic read" }
47+
48+ override string toString ( ) { result = ssa .toString ( ) }
49+
50+ override Location getLocation ( ) { result = ssa .getLocation ( ) }
51+ }
52+
53+ /** Gets the Go data-flow node corresponding to `n`. */
54+ Node getNodeFromSsaNode ( SsaFlow:: Node n ) {
55+ result .( SsaNode ) .getDefinition ( ) = n .( SsaFlow:: SsaDefinitionNode ) .getDefinition ( )
56+ or
57+ result .( SsaSynthReadNode ) .getSsaNode ( ) = n
58+ or
59+ exists ( IR:: Instruction insn , SsaSourceVariable v |
60+ n .( SsaFlow:: ReadNode ) .readsAt ( insn , v ) and
61+ insn .reads ( v ) and
62+ result .asInstruction ( ) = insn
63+ )
64+ or
65+ exists ( IR:: Instruction insn , SsaSourceVariable v |
66+ n .( SsaFlow:: PostUpdateReadNode ) .readsAt ( insn , v ) and
67+ insn .reads ( v ) and
68+ result .( PostUpdateNode ) .getPreUpdateNode ( ) .asInstruction ( ) = insn
69+ )
70+ or
71+ exists ( IR:: Instruction rhs |
72+ rhs =
73+ n .( SsaFlow:: WriteDefSourceNode ) .getDefinition ( ) .( SsaExplicitWrite ) .getDefinition ( ) .getRhs ( )
74+ |
75+ result .asInstruction ( ) = rhs
76+ or
77+ result .( PostUpdateNode ) .getPreUpdateNode ( ) .asInstruction ( ) = rhs
78+ )
79+ }
80+
2981 /** Gets the callable in which this node occurs. */
3082 DataFlowCallable nodeGetEnclosingCallable ( Node n ) {
3183 result .asCallable ( ) = n .getEnclosingCallable ( )
0 commit comments