@@ -11,7 +11,54 @@ private newtype TNode =
11
11
MkSsaNode ( SsaDefinition ssa ) or
12
12
MkGlobalFunctionNode ( Function f ) or
13
13
MkImplicitVarargsSlice ( CallExpr c ) { c .hasImplicitVarargs ( ) } or
14
- MkFlowSummaryNode ( FlowSummaryImpl:: Private:: SummaryNode sn )
14
+ MkFlowSummaryNode ( FlowSummaryImpl:: Private:: SummaryNode sn ) or
15
+ MkPostUpdateNode ( IR:: Instruction insn ) { insn = updatedInstruction ( ) }
16
+
17
+ private IR:: Instruction getADirectlyWrittenInstruction ( ) {
18
+ exists ( IR:: WriteTarget target , IR:: Instruction base |
19
+ target = any ( IR:: WriteInstruction w ) .getLhs ( ) and
20
+ ( base = result or base = IR:: implicitDerefInstruction ( result .( IR:: EvalInstruction ) .getExpr ( ) ) )
21
+ |
22
+ target .( IR:: FieldTarget ) .getBase ( ) = base or
23
+ target .( IR:: ElementTarget ) .getBase ( ) = base
24
+ )
25
+ or
26
+ result = IR:: evalExprInstruction ( any ( SendStmt s ) .getChannel ( ) )
27
+ }
28
+
29
+ private IR:: Instruction getAccessPathPredecessor2 ( IR:: Instruction insn ) {
30
+ exists ( Expr e | result = IR:: evalExprInstruction ( e ) |
31
+ e = insn .( IR:: EvalInstruction ) .getExpr ( ) .( UnaryExpr ) .getOperand ( )
32
+ or
33
+ e = insn .( IR:: EvalInstruction ) .getExpr ( ) .( StarExpr ) .getBase ( )
34
+ or
35
+ e = insn .( IR:: EvalImplicitDerefInstruction ) .getOperand ( )
36
+ )
37
+ or
38
+ result = insn .( IR:: ComponentReadInstruction ) .getBase ( )
39
+ }
40
+
41
+ private IR:: Instruction getAWrittenInstruction ( ) {
42
+ result = getAccessPathPredecessor2 * ( getADirectlyWrittenInstruction ( ) )
43
+ }
44
+
45
+ private IR:: Instruction updatedInstruction ( ) {
46
+ result = IR:: evalExprInstruction ( updatedExpr ( ) ) or
47
+ result instanceof IR:: EvalImplicitDerefInstruction or
48
+ result = getAWrittenInstruction ( )
49
+ }
50
+
51
+ private Expr updatedExpr ( ) {
52
+ result instanceof AddressExpr
53
+ or
54
+ result = any ( AddressExpr e ) .getOperand ( )
55
+ or
56
+ result instanceof StarExpr
57
+ or
58
+ result instanceof DerefExpr
59
+ or
60
+ result = any ( CallExpr ce ) .getAnArgument ( ) and mutableType ( result .getType ( ) )
61
+ }
15
62
16
63
/** Nodes intended for only use inside the data-flow libraries. */
17
64
module Private {
@@ -734,6 +781,10 @@ module Public {
734
781
)
735
782
}
736
783
784
+ private class UpdateNode extends InstructionNode {
785
+ UpdateNode ( ) { insn = updatedInstruction ( ) }
786
+ }
787
+
737
788
/**
738
789
* A node associated with an object after an operation that might have
739
790
* changed its state.
@@ -753,35 +804,35 @@ module Public {
753
804
abstract Node getPreUpdateNode ( ) ;
754
805
}
755
806
756
- private class DefaultPostUpdateNode extends PostUpdateNode {
757
- Node preupd ;
807
+ class DefaultPostUpdateNode extends PostUpdateNode {
808
+ UpdateNode preupd ;
758
809
759
- DefaultPostUpdateNode ( ) {
760
- (
761
- preupd instanceof AddressOperationNode
762
- or
763
- preupd = any ( AddressOperationNode addr ) .getOperand ( )
764
- or
765
- preupd = any ( PointerDereferenceNode deref ) .getOperand ( )
766
- or
767
- preupd = getAWrittenNode ( )
768
- or
769
- (
770
- preupd instanceof ArgumentNode and not preupd instanceof ImplicitVarargsSlice
771
- or
772
- preupd = any ( CallNode c ) .getAnImplicitVarargsArgument ( )
773
- ) and
774
- mutableType ( preupd .getType ( ) )
775
- ) and
776
- (
777
- preupd = this .( SsaNode ) .getAUse ( )
778
- or
779
- preupd = this and
780
- not basicLocalFlowStep ( _, this )
781
- )
782
- }
810
+ DefaultPostUpdateNode ( ) { this = MkPostUpdateNode ( preupd .asInstruction ( ) ) }
783
811
784
812
override Node getPreUpdateNode ( ) { result = preupd }
813
+
814
+ Node getSuccessor ( ) {
815
+ preupd = result .( SsaNode ) .getAUse ( )
816
+ or
817
+ preupd = result and
818
+ not basicLocalFlowStep0 ( _, preupd )
819
+ }
820
+
821
+ override ControlFlow:: Root getRoot ( ) { result = preupd .asInstruction ( ) .getRoot ( ) }
822
+
823
+ override Type getType ( ) { result = preupd .asInstruction ( ) .getResultType ( ) }
824
+
825
+ override string getNodeKind ( ) { result = "post-update node" }
826
+
827
+ override string toString ( ) {
828
+ result = "post-update node for " + preupd .asInstruction ( ) .toString ( )
829
+ }
830
+
831
+ override predicate hasLocationInfo (
832
+ string filepath , int startline , int startcolumn , int endline , int endcolumn
833
+ ) {
834
+ preupd .asInstruction ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
835
+ }
785
836
}
786
837
787
838
/**
0 commit comments