[Mono-bugs] [Bug 479209] New: [Regression] Compiler generates invalid code on certain inputs

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Feb 24 14:42:43 EST 2009


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


           Summary: [Regression] Compiler generates invalid code on
                    certain inputs
    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 come C# code:

---
using System;

public sealed class Thing<TFirst> where TFirst : class
{
    public static Thing<TFirst> Create<TSecond>(Func<TFirst, TSecond> fn)
        where TSecond : class
    {
        return new Thing<TFirst>(
            delegate(TFirst item)
            {
                TSecond foo = item == null ? null : fn(item);
                Console.WriteLine(foo);
            });
    }

    public void SomeAction()
    {
        _fn(null);
    }

    private Thing(Action<TFirst> fn)
    {
        _fn = fn;
    }

    Action<TFirst> _fn;
}

public static class Program
{
    public static void Main()
    {
        var foo = Thing<object>.Create(x => x);
        foo.SomeAction();
    }
}
---

Under the 2.2 compiler, this emits valid code, but in the most recent SVN
revisions, it emits code that fails to run correctly under either Mono or
MS.NET. When attempting to run under mono, this is the program output:

---
**
ERROR:method-to-ir.c:2531:emit_get_rgctx: assertion failed:
(method->is_inflated && mono_method_get_context (method)->method_inst)
Stacktrace:

  at Thing`1<object>.SomeAction () <0xffffffff>
  at Thing`1<object>.SomeAction () <0x0003b>
  at Program.Main () <0x00065>
  at (wrapper runtime-invoke) object.runtime_invoke_void
(object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

    0   mono                                0x00088321
mono_handle_native_sigsegv + 241
    1   libSystem.B.dylib                   0x965f72bb _sigtramp + 43
    2   ???                                 0xffffffff 0x0 + 4294967295
    3   libSystem.B.dylib                   0x9666b23a raise + 26
    4   libSystem.B.dylib                   0x96677679 abort + 73
    5   libglib-2.0.0.1800.1.dylib          0x0037bf74 g_assertion_message +
253
    6   libglib-2.0.0.1800.1.dylib          0x0037c4b6 g_assertion_message_expr
+ 87
    7   mono                                0x000114af
mono_decompose_array_access_opts + 3519
    8   mono                                0x00011a8f
mono_decompose_array_access_opts + 5023
    9   mono                                0x00028522 mono_method_to_ir +
51426
    10  mono                                0x00006e73 mini_method_compile +
499
    11  mono                                0x0000938f mini_method_compile +
9999
    12  mono                                0x00089c48 mono_delegate_trampoline
+ 504
    13  ???                                 0x00439574 0x0 + 4429172
    14  ???                                 0x004922ee 0x0 + 4793070
    15  ???                                 0x004921fa 0x0 + 4792826
    16  mono                                0x001397eb mono_runtime_exec_main +
251
    17  mono                                0x0013de83 mono_runtime_run_main +
339
    18  mono                                0x00066533 mono_main + 6083
    19  mono                                0x00001ee6 start + 54
    20  ???                                 0x00000002 0x0 + 2

Debug info from gdb:


=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================


Debug info from gdb:


=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================

Abort trap


Reproducible: Always

Steps to Reproduce:
1. Compile the included code with a recent svn build of gmcs
2. Run it
3.
Actual Results:  
mono crashes because the executable image is faulty.

Expected Results:  
gmcs should produce an executable image that mono can execute.

Upon dissassembling the code produced by both versions using monodis, the
problem seems to be on line 112 of the 2.4 code, which corresponds to line
IL_000c, below:

---
    // method line 7
    .method assembly hidebysig 
           instance default void '<>m__0' (!TFirst item)  cil managed 
    {
        // Method begins at RVA 0x2180
    // Code size 47 (0x2f)
    .maxstack 5
    .locals init (
        !TSecond    V_0)
    IL_0000:  ldarg.1 
    IL_0001:  box !0
    IL_0006:  brtrue IL_0016

    IL_000b:  ldnull 
    IL_000c:  unbox.any !!0
    IL_0011:  br IL_0022

    IL_0016:  ldarg.0 
    IL_0017:  ldfld class [System.Core]System.Func`2<!0,!1> class
Thing`1/'<Create>c__AnonStorey0`1'<!0,!1>::fn
    IL_001c:  ldarg.1 
    IL_001d:  callvirt instance !1 class [System.Core]System.Func`2<!TFirst,
!TSecond>::Invoke(!0)
    IL_0022:  stloc.0 
    IL_0023:  ldloc.0 
    IL_0024:  box !1
    IL_0029:  call void class [mscorlib]System.Console::WriteLine(object)
    IL_002e:  ret 
    } // end of method <Create>c__AnonStorey0`1::<>m__0
---

>From what I can tell, !!0 is an invalid type token. using !0 or !1 instead (or
removing the line entirely) and reassembling both produce a valid image; I
*believe* the !1 is more appropriate here, but my understanding of il is not
strong enough for me to be entirely certain.

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