[Mono-bugs] [Bug 478313] New: [Regression] Compiler generates invalid code for classes with generic class constraint

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Feb 20 14:11:20 EST 2009


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


           Summary: [Regression] Compiler generates invalid code for
                    classes with generic class constraint
    Classification: Mono
           Product: Mono: Compilers
           Version: SVN
          Platform: Macintosh
        OS/Version: Mac OS X 10.5
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: dmitchell at logos.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us)
AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1

Here's some code:

---


using System;

namespace MonoBug
{
    public class GenericClass<T1>
        where T1 : class
    {
        public void Method()
        {
            T1 refCurrentMerge = default(T1);
        }
    }

    public static class Program
    {
        public static void Main()
        {
            Console.WriteLine("entered main");
            var foo = new GenericClass<object>();
            Console.WriteLine("created foo; it is {0}", foo);
            foo.Method();
            Console.WriteLine("performed method");
        }
    }
}

---

This code compiles with no errors (one warning) in both gmcs 2.2 and gmcs from
svn, but svn's gmcs produces invalid il that causes a crash at runtime.

Reproducible: Always

Steps to Reproduce:
1. Put the included code into a file
2. Compile with gmcs created from svn
3. Run the executable produced by gmcs
Actual Results:  
Application crashes

Expected Results:  
Application should run.

By disassembling the executables produced by the two versions of gmcs, I was
able determine that an additional instruction was added to the implementation
of Method() in the svn version. Here's what 2.2 produces:

    .method public hidebysig 
           instance default void Method ()  cil managed 
    {
        // Method begins at RVA 0x20f4
    // Code size 3 (0x3)
    .maxstack 1
    .locals init (
        !T1    V_0)
    IL_0000:  ldnull 
    IL_0001:  stloc.0 
    IL_0002:  ret 
    } 

and here's what svn produces:

method public hidebysig 
           instance default void Method ()  cil managed 
    {
        // Method begins at RVA 0x20f4
    // Code size 8 (0x8)
    .maxstack 2
    .locals init (
        !T1    V_0)
    IL_0000:  ldnull 
    IL_0001:  unbox.any !0
    IL_0006:  stloc.0 
    IL_0007:  ret 
    }

---

I suspect that the unbox.any instruction is what is causing the error. Also
noteworthy is that removing the generic constraint from GenericClass causes the
compiler (either version) to emit valid il.

-- 
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