[Mono-bugs] [Bug 677550] New: Fixed buffers are broken

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Mar 7 16:35:32 EST 2011


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

https://bugzilla.novell.com/show_bug.cgi?id=677550#c0


           Summary: Fixed buffers are broken
    Classification: Mono
           Product: Mono: Compilers
           Version: unspecified
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: msafar at novell.com
        ReportedBy: rkumpera at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Compile the following program:

using System;

public unsafe struct Foo {
    public fixed int bar[10];
}

public unsafe class Driver {
    public static void Main () {
        Foo f = new Foo ();
        f.bar[5] = 10;
        Console.WriteLine (f.bar [5]);
    }
}


The resulting assembly has a few issues. First, the IL to do indexing is wrong:

    IL_0008:  ldloca.s 0
    IL_000a:  ldflda valuetype Foo/'<bar>__FixedBuffer0' Foo::bar
    IL_000f:  ldflda valuetype Foo/'<bar>__FixedBuffer0' Foo::bar
    IL_0014:  ldc.i4.s 0x14
    IL_0016:  add 
    IL_0017:  ldc.i4.s 0x0a
    IL_0019:  stind.i4 


CSC generates the following:


    IL_0009:  ldloca.s 0
    IL_000b:  ldflda valuetype Foo/'<bar>e__FixedBuffer0' Foo::bar
1)The second ldflda on mcs code is wrong.
    IL_0010:  ldflda int32 Foo/'<bar>e__FixedBuffer0'::FixedElementField
2)mcs doesn't convert the managed pointer to intptr
    IL_0015:  conv.u 
    IL_0016:  ldc.i4.s 0x14
3)mcs doesn't convert int to intptr
    IL_0018:  conv.i 
    IL_0019:  add 
    IL_001a:  ldc.i4.s 0x0a
    IL_001c:  stind.i4 

Issues 2 and 3 and not strictly required.

The second issue is with the generated fixed buffer type.

MCS generates:

  .class nested public sequential ansi sealed beforefieldinit
'<bar>__FixedBuffer0'
      extends [mscorlib]System.ValueType
  {
    .custom instance void class
[mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'()
=  (01 00 00 00 ) // ....

    .custom instance void class
[mscorlib]System.Runtime.CompilerServices.UnsafeValueTypeAttribute::'.ctor'() =
 (01 00 00 00 ) // ....

    .pack 0
    .size 10
    .field  public  int32 FixedElementField

  } // end of class <bar>__FixedBuffer0



CSC generates:

  .class nested public sequential ansi sealed beforefieldinit
'<bar>e__FixedBuffer0'
      extends [mscorlib]System.ValueType
  {
    .custom instance void class
[mscorlib]System.Runtime.CompilerServices.UnsafeValueTypeAttribute::'.ctor'() =
 (01 00 00 00 ) // ....

    .custom instance void class
[mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'()
=  (01 00 00 00 ) // ....

    .pack 0
    .size 40
    .field  public  int32 FixedElementField

  } // end of class <bar>e__FixedBuffer0


Notice that MCS generates a type 4x smaller than it must be.

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


More information about the mono-bugs mailing list