[nem-bug] [Nemerle 0000603]: callvirt is emitted when call is
sufficient
feedback at nemerle.org
feedback at nemerle.org
Sat Feb 11 12:09:04 CET 2006
A NOTE has been added to this issue.
======================================================================
<https://nemerle.org/bugs/view.php?id=603>
======================================================================
Reported By: nazgul
Assigned To:
======================================================================
Project: Nemerle
Issue ID: 603
Category: Compiler
Reproducibility: always
Severity: minor
Priority: normal
Status: confirmed
======================================================================
Date Submitted: 01-26-2006 21:34 CET
Last Modified: 02-11-2006 12:09 CET
======================================================================
Summary: callvirt is emitted when call is sufficient
Description:
#pragma indent
using System
class A
public foo () : void
()
A().foo ()
produces:
...
IL_0000: newobj instance void A::.ctor()
IL_0005: callvirt instance void A::foo()
IL_000a: ret
...
======================================================================
----------------------------------------------------------------------
nazgul - 02-11-06 11:19
----------------------------------------------------------------------
This patch seems to fix the basic behaviour, but it causes strange
regressions in frommcs testcases, like:
[IL]: Error: [C:\cygwin\home\nazgul\nemerle\ncc\testsuite\test-147.exe :
Test::Main][offset 0x00000037] The 'this' parameter to the call must be
the calling method's 'this' parameter.
1 Error Verifying ../test-147.exe
My guess is that it is unrelated to callvirt, which must have just hidden
the real bug...
----------------------------------------------------------------------
nazgul - 02-11-06 11:42
----------------------------------------------------------------------
Funny, csc seems to emit 'call' only in cases when it knows for sure, that
the object is actual class, which we are trying to call. If it is first
stored for example in local variable, then it emits 'callvirt' even when
not calling virtual methods.
So it is probably optimized by runtime.
----------------------------------------------------------------------
steffen - 02-11-06 12:01
----------------------------------------------------------------------
As far as I know the difference between call and callvirt when calling
non-virtual functions is that callvirt checks whether the called instance
is null while call doesn't.
So if you compile the following C# program:
public class A {
public void f() {
System.Console.WriteLine(this == null);
}
public static void Main() {
((A)null).f();
}
}
and disassemble it and replace the line
IL_0001: callvirt instance void class A::f()
by
IL_0001: call instance void class A::f()
it will run and output
True
----------------------------------------------------------------------
nazgul - 02-11-06 12:09
----------------------------------------------------------------------
Nice! I didn't know that. Also 'call' is emitted for "base" calls in
override method chain, so it seems that only there it makes difference in
"virtual" way of calling the method.
Issue History
Date Modified Username Field Change
======================================================================
01-26-06 21:34 nazgul New Issue
02-11-06 11:18 nazgul Status new => confirmed
02-11-06 11:18 nazgul Description Updated
02-11-06 11:18 nazgul Additional Information Updated
02-11-06 11:18 nazgul File Added: nonvirt.patch
02-11-06 11:19 nazgul Note Added: 0001077
02-11-06 11:42 nazgul Note Added: 0001078
02-11-06 12:01 steffen Note Added: 0001079
02-11-06 12:09 nazgul Note Added: 0001080
======================================================================
More information about the bugs
mailing list