[Mono-bugs] [Bug 573312] New: mono compiler compiles struct in fixed block wrong?

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Jan 23 15:01:03 EST 2010


http://bugzilla.novell.com/show_bug.cgi?id=573312

http://bugzilla.novell.com/show_bug.cgi?id=573312#c0


           Summary: mono compiler compiles struct in fixed block wrong?
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.6.x
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: post-christian at freenet.de
         QAContact: mono-bugs at lists.ximian.com
                CC: post-christian at freenet.de
          Found By: ---
           Blocker: ---


Description of Problem:

The structures in the code below get different values in fixed block. It does
not occur when the script is compiled with the Microsoft .Net compiler.

Steps to reproduce the problem:

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

class FixedTest
{
    [StructLayout( LayoutKind.Explicit )]
    public unsafe struct Value
    {
        [FieldOffset( 0 )]
        public void* p;
        [FieldOffset( 0 )]
        public double n;
        [FieldOffset( 0 )]
        public long i;
        [FieldOffset( 0 )]
        public bool b;
    }

    public enum ValueType
    {
        Null = 0,
        Boolean = 1,
        Integer = 2,
        Float = 3,
    }

    [StructLayout( LayoutKind.Explicit, Pack = 4 )]
    public unsafe struct TValue
    {
        public Value value;
        public ValueType type;

        public TValue( long x ) {
            value = new Value();
            value.i = x;
            type = ValueType.Integer;
        }

        public TValue( double x ) {
            value = new Value();
            value.n = x;
            type = ValueType.Float;
        }

        public TValue( bool x ) {
            value = new Value();
            value.b = x;
            type = ValueType.Boolean;
        }

        public override string ToString() {
            switch( type ) {
            case ValueType.Null:
                return "(null)";
            case ValueType.Integer:
                return "(int) " + value.i.ToString();
            case ValueType.Float:
                return "(float) " + value.n.ToString();
            case ValueType.Boolean:
                return "(bool) " + (value.b ? "True" : "False");
            }
            return base.ToString();
        }

    }

    public static unsafe void Main( string[] arg ) {
        TValue[] values = new TValue[10];
        values[0] = new TValue( 0L );
        values[1] = new TValue( 1000L );
        values[2] = new TValue( 1L );
        Console.WriteLine( "values: {0} {1} {2}", values[0], values[1],
values[2] );
        fixed( TValue* vals = values ) {
            Console.WriteLine( "fixed: {0} {1} {2}", vals[0], vals[1], vals[2]
);
        }
    }
}


Actual Results:

values: (int) 0 (int) 1000 (int) 1
fixed: (int) 0 (int) 1000 (int) 1000


Expected Results:

values: (int) 0 (int) 1000 (int) 1
fixed: (int) 0 (int) 1000 (int) 1

How often does this happen? 

every time

-- 
Configure bugmail: http://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