[Mono-bugs] [Bug 457489] New: Compiler creates invalid/unverifiable constructor code

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Dec 8 20:00:19 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=457489


           Summary: Compiler creates invalid/unverifiable constructor code
           Product: Mono: Compilers
           Version: unspecified
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: gnorton at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


The follow snippet:

using System;

namespace Bug
{
        public class A : B
        {
                public A ()
                {
                        var dingus = new B ();

                        dingus.Event += delegate {
                                // Comment me and a valid ctor is generated
                                int prop = dingus.Prop;
                        };
                }
        }

        public class B
        {
                public B ()
                {
                }

                public int Prop { get; set; }

                public event EventHandler Event;
        }

        public delegate void EventHandler ();
}


Generates the following IL on mono:

    .method public hidebysig  specialname  rtspecialname 
           instance default void '.ctor' ()  cil managed 
    {
        // Method begins at RVA 0x20ec
        // Code size 47 (0x2f)
        .maxstack 6
        .locals init (
                class Bug.A/'<A>c__AnonStorey0' V_0)
        IL_0000:  newobj instance void class
Bug.A/'<A>c__AnonStorey0'::'.ctor'()
        IL_0005:  stloc.0 
        IL_0006:  ldarg.0 
        IL_0007:  call instance void class Bug.B::'.ctor'()
        IL_000c:  ldloc.0 
        IL_000d:  newobj instance void class Bug.B::'.ctor'()
        IL_0012:  stfld class Bug.B Bug.A/'<A>c__AnonStorey0'::dingus
        IL_0017:  ldloc.0 
        IL_0018:  ldfld class Bug.B Bug.A/'<A>c__AnonStorey0'::dingus
        IL_001d:  ldloc.0 
        IL_001e:  ldftn instance void class
Bug.A/'<A>c__AnonStorey0'::'<>m__0'()
        IL_0024:  newobj instance void class Bug.EventHandler::'.ctor'(object,
native int)
        IL_0029:  callvirt instance void class Bug.B::add_Event(class
Bug.EventHandler)
        IL_002e:  ret 
    } // end of method A::.ctor

The IL from csc is:

    .method public hidebysig  specialname  rtspecialname 
           instance default void '.ctor' ()  cil managed 
    {
        // Method begins at RVA 0x20d4
        // Code size 51 (0x33)
        .maxstack 4
        .locals init (
                class Bug.A/'<>c__DisplayClass1'        V_0)
        IL_0000:  ldarg.0 
        IL_0001:  call instance void class Bug.B::'.ctor'()
        IL_0006:  nop 
        IL_0007:  newobj instance void class
Bug.A/'<>c__DisplayClass1'::'.ctor'()
        IL_000c:  stloc.0 
        IL_000d:  nop 
        IL_000e:  ldloc.0 
        IL_000f:  newobj instance void class Bug.B::'.ctor'()
        IL_0014:  stfld class Bug.B Bug.A/'<>c__DisplayClass1'::dingus
        IL_0019:  ldloc.0 
        IL_001a:  ldfld class Bug.B Bug.A/'<>c__DisplayClass1'::dingus
        IL_001f:  ldloc.0 
        IL_0020:  ldftn instance void class
Bug.A/'<>c__DisplayClass1'::'<.ctor>b__0'()
        IL_0026:  newobj instance void class Bug.EventHandler::'.ctor'(object,
native int)
        IL_002b:  callvirt instance void class Bug.B::add_Event(class
Bug.EventHandler)
        IL_0030:  nop 
        IL_0031:  nop 
        IL_0032:  ret 
    } // end of method A::.ctor

You can see clearly the gmcs/smcs emitted IL is invalid as it doesnt call the
base ctor, leaving `this` uninitialized.

The error from peverify is:

[IL]: Error: [layout.dll : layout.PAge::.ctor][0ffset 0x00000008][found
<uninitialized> ref ('this' ptr) 'layout.Page'] Uninitialized item on stack.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list