Bring jbevain/cecil's commit dfb8329f5ac41f7eaffaef00d3de8b75f4308c87, Fix ComputeSta...
authorMiguel de Icaza <miguel@gnome.org>
Wed, 18 Apr 2012 22:48:29 +0000 (18:48 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Wed, 18 Apr 2012 22:54:19 +0000 (18:54 -0400)
mcs/class/Mono.Cecil/Mono.Cecil.Cil/CodeWriter.cs

index b2d1ae7178243646296e65197c6527497a896b56..ac093cae4602d9561078ab9e78df22fb48e75a91 100644 (file)
@@ -424,10 +424,18 @@ namespace Mono.Cecil.Cil {
                        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: