Permalink
Browse files

Fix ComputeStackDelta() for calli instruction.

  • Loading branch information...
1 parent 1d446c7 commit dfb8329f5ac41f7eaffaef00d3de8b75f4308c87 @dgrunwald dgrunwald committed Aug 6, 2011
Showing with 12 additions and 4 deletions.
  1. +12 −4 Mono.Cecil.Cil/CodeWriter.cs
@@ -424,10 +424,18 @@ static void ComputeStackDelta (Instruction instruction, ref int stack_size)
switch (instruction.opcode.FlowControl) {
case FlowControl.Call: {
var method = (IMethodSignature) instruction.operand;
- stack_size -= (method.HasParameters ? method.Parameters.Count : 0)
- + (method.HasImplicitThis () && instruction.opcode.Code != Code.Newobj ? 1 : 0);
- stack_size += (method.ReturnType.etype == ElementType.Void ? 0 : 1)
- + (method.HasThis && instruction.opcode.Code == Code.Newobj ? 1 : 0);
+ // pop 'this' argument
+ if (method.HasImplicitThis() && instruction.opcode.Code != Code.Newobj)
+ stack_size--;
+ // pop normal arguments
+ if (method.HasParameters)
+ stack_size -= method.Parameters.Count;
+ // pop function pointer
+ if (instruction.opcode.Code == Code.Calli)
+ stack_size--;
+ // push return value
+ if (method.ReturnType.etype != ElementType.Void || instruction.opcode.Code == Code.Newobj)
+ stack_size++;
break;
}
default:

0 comments on commit dfb8329

Please sign in to comment.