[Mono-bugs] [Bug 389073] New: Bad IntPtr typecast

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri May 9 21:25:26 EDT 2008


           Summary: Bad IntPtr typecast
           Product: Mono: Compilers
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: spouliot at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

gmcs compile this code
        private long CastUIntPtrToInt64 (UIntPtr ptr)
                return (long) ptr;
into this
        IL_0000: ldarg.1 
        IL_0001: call System.UInt32 System.UIntPtr::op_Explicit(System.UIntPtr)
        IL_0006: conv.u8 
        IL_0007: ret 
Converting to U8 (why not I8 ?) won't give back the 32bits lost, which is a
problem on all 64bits platforms.

MS csc generates this
        L_0000: ldarg.1 
        L_0001: call uint64 [mscorlib]System.UIntPtr::op_Explicit(native
unsigned int)
        L_0006: ret 

Another case (not as bad) is:

System.UInt32 CastIntPtrToUInt32(System.IntPtr)
        IL_0000: ldarg.1 
        IL_0001: call System.Int64 System.IntPtr::op_Explicit(System.IntPtr)
        IL_0006: conv.u4 
        IL_0007: ret 
        L_0000: ldarg.1 
        L_0001: call int32 [mscorlib]System.IntPtr::op_Explicit(native int)
        L_0006: ret 

There could be other cases too... they just did not trigger my new rule :-)

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