@@ -118,6 +118,10 @@ LinkedList<Instruction[]> SpiltStatements(InstrBlock block, Trace trace, CFConte
118
118
var statements = new LinkedList < Instruction [ ] > ( ) ;
119
119
var currentStatement = new List < Instruction > ( ) ;
120
120
121
+ // Instructions that must be included in the ccurrent statement to ensure all outgoing
122
+ // branches have stack = 0
123
+ var requiredInstr = new HashSet < Instruction > ( ) ;
124
+
121
125
for ( int i = 0 ; i < block . Instructions . Count ; i ++ ) {
122
126
Instruction instr = block . Instructions [ i ] ;
123
127
currentStatement . Add ( instr ) ;
@@ -128,10 +132,21 @@ LinkedList<Instruction[]> SpiltStatements(InstrBlock block, Trace trace, CFConte
128
132
case FlowControl . Cond_Branch :
129
133
case FlowControl . Return :
130
134
case FlowControl . Throw :
135
+ if ( trace . AfterStack [ instr . Offset ] != 0 ) {
136
+ if ( instr . Operand is Instruction )
137
+ requiredInstr . Add ( ( Instruction ) instr . Operand ) ;
138
+ else {
139
+ foreach ( var target in ( Instruction [ ] ) instr . Operand )
140
+ requiredInstr . Add ( target ) ;
141
+ shouldSpilt = false ;
142
+ }
143
+ }
131
144
shouldSpilt = true ;
132
145
break ;
133
146
}
134
- if ( ( instr . OpCode . OpCodeType != OpCodeType . Prefix && trace . AfterStack [ instr . Offset ] == 0 ) &&
147
+ requiredInstr . Remove ( instr ) ;
148
+ if ( ( instr . OpCode . OpCodeType != OpCodeType . Prefix && trace . AfterStack [ instr . Offset ] == 0 &&
149
+ requiredInstr . Count == 0 ) &&
135
150
( shouldSpilt || ctx . Intensity > ctx . Random . NextDouble ( ) ) ) {
136
151
statements . AddLast ( currentStatement . ToArray ( ) ) ;
137
152
currentStatement . Clear ( ) ;
0 commit comments