File tree Expand file tree Collapse file tree 1 file changed +18
-3
lines changed
Expand file tree Collapse file tree 1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -223,8 +223,20 @@ public int[] TraceArguments(Instruction instr) {
223223 while ( working . Count > 0 ) {
224224 int index = working . Dequeue ( ) ;
225225 while ( index >= 0 ) {
226- if ( BeforeStackDepths [ index ] == targetStack )
227- break ;
226+ if ( BeforeStackDepths [ index ] == targetStack ) {
227+ if ( method . Body . Instructions [ index ] . OpCode . Code != Code . Dup ) {
228+ // It's not a duplicate instruction, this is an acceptable start point.
229+ break ;
230+ } else {
231+ var prevInstr = method . Body . Instructions [ index - 1 ] ;
232+ prevInstr . CalculateStackUsage ( out push , out _ ) ;
233+ if ( push > 0 ) {
234+ // A duplicate instruction is an acceptable start point in case the preceeding instruction
235+ // pushes a value.
236+ break ;
237+ }
238+ }
239+ }
228240
229241 if ( fromInstrs . ContainsKey ( index ) )
230242 foreach ( Instruction fromInstr in fromInstrs [ index ] ) {
@@ -270,8 +282,11 @@ public int[] TraceArguments(Instruction instr) {
270282 evalStack . Push ( lastIdx ) ;
271283 }
272284 else {
285+ // Removing values from the stack. If the stack is already empty, the poped values are of no relevance.
286+ Debug . Assert ( evalStack . Count >= pop ) ;
273287 for ( var i = 0 ; i < pop ; i ++ ) {
274- evalStack . Pop ( ) ;
288+ if ( evalStack . Count > 0 )
289+ evalStack . Pop ( ) ;
275290 }
276291 Debug . Assert ( push <= 1 ) ; // Instructions shouldn't put more than one value on the stack.
277292 for ( var i = 0 ; i < push ; i ++ ) {
You can’t perform that action at this time.
0 commit comments