[Mono-bugs] [Bug 657623] New: gmcs sees "is" operator as always true (and removes all subsequent code)

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Dec 5 11:39:25 EST 2010


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

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


           Summary: gmcs sees "is" operator as always true (and removes
                    all subsequent code)
    Classification: Mono
           Product: Mono: Compilers
           Version: SVN
          Platform: x86
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: msafar at novell.com
        ReportedBy: andyhume32 at yahoo.co.uk
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=403493)
 --> (http://bugzilla.novell.com/attachment.cgi?id=403493)
Example source

User-Agent:       Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;
Trident/4.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET
CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR
3.5.30729; .NET4.0C; .NET4.0E)

Tested in mono 2.8 (Linux), and cygwin built from a week or so ago.

Sample method:
[[
    internal static IntPtr Bar<T>(IntPtr x, T val)
        where T : struct
    {
        if (val is IntPtr) throw new ArgumentException("xxxx1");
        if (typeof(T) == typeof(IntPtr)) throw new ArgumentException("xxxx2");
        //
        Console.WriteLine("Success, type is: {0} / {1}",
            typeof(T).Name, val.GetType().Name);
        return IntPtr.Zero;
    }]]


gmcs/dmcs both output the following, whereas MSFT csc reports no
warnings/errors:
[[
gmcsIsIntPtr.cs(19,17): warning CS0183: The given expression is always of the
provided (`System.IntPtr') type
gmcsIsIntPtr.cs(20,9): warning CS0162: Unreachable code detected
Compilation succeeded - 2 warning(s)
]]

Clearly that is wrong, "val" can be any value type.

Running the exe and inspection of its IL shows that gmcs has compiled the
method to one throw statement and has thus removed all of the code.

Adding a Main that calls the method with Boolean, Int32 and IntPtr argument and
running the two compiled samples shows this too.  For csc compiled:
[[
D:\Temp>gmcsIsIntPtr_msft2.exe
Success, type is: Boolean / System.Boolean
Success, type is: Int32 / System.Int32

Unhandled Exception: System.ArgumentException: xxxx1
   at Foo.Bar[T](IntPtr x, T val)
   at Foo.Main()

D:\Temp>
]]

For Mono compiled:
[[
anby at linux5:~/dev> mono --debug gmcsIsIntPtr_gmcs2_8_LinuxVm.exe 

Unhandled Exception: System.ArgumentException: xxxx1
  at Foo.Main () [0x00000] in <filename unknown>:0 
andy at linux5:~/dev>
]]

Reproducible: Always

Steps to Reproduce:
Compile as described in details, see no warning as described.  When run, get
two 'good' output lines and exception as described in details.

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