[Mono-bugs] [Bug 675777] New: the negation part of an expression like "0 - non_constant_expr" is ignored by mcs

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Feb 28 19:42:51 EST 2011


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

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


           Summary: the negation part of an expression like "0 -
                    non_constant_expr" is ignored by mcs
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.10.x
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: msafar at novell.com
        ReportedBy: treeki at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


Created an attachment (id=416668)
 --> (http://bugzilla.novell.com/attachment.cgi?id=416668)
test case 

User-Agent:       Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.7.62
Version/11.01

If an expression in this form is used, then mcs will generate invalid code:
0 - (some expression that is not made up entirely of constant values)

For example:
int ten = 10;
Console.WriteLine("This should output -10, but doesn't: {0}", 0 - ten);

If the minuend (0) is a variable or not 0, and/or the subtrahend (ten) is a
constant, then the issue does not occur. Microsoft's C# compiler does not have
this issue.


Please see the actual/expected output below for more info on this.

It only occurs when the test case is compiled with mcs -- whether the compiled
exe is run using Mono's CLR or Microsoft's CLR has no bearing on the output.

I checked both binaries using monodis, the code is virtually identical -- but
Microsoft's compiler inserts a "neg" instruction, whereas mcs doesn't (the
variable is passed directly to Console::WriteLine).

Also, the problem does not occur when just using a negating expression like
-ten.


I've tested using Mono 2.10.1 on Arch Linux 64-bit, and Visual Studio 2008 on
Windows XP 32-bit.

Reproducible: Always

Steps to Reproduce:
1. Compile the test case, using either mcs (for incorrect output) or
Microsoft's csc (for correct output).
2. Run the .exe file in a console.
Actual Results:  
When the assembly is compiled with mcs:
-1 - ten: -11
 0 - ten: 10
 1 - ten: -9
   - ten: -10

-1 - 10: -11
 0 - 10: -10
 1 - 10: -9
   - 10: -10

minusOne - 10: -11
    zero - 10: -10
     one - 10: -9

minusOne - ten: -11
    zero - ten: -10
     one - ten: -9

(4 - 4) - 10:          -10 [works under mcs]
      0 - (5 * 2):     -10 [works under mcs]
      0 - (ten):       10 [fails under mcs]
      0 - (ten * 2):   20 [fails under mcs]
      0 - (ten * one): 10 [fails under mcs]


Expected Results:  
When the assembly is compiled with csc or Visual C#:
-1 - ten: -11
 0 - ten: -10
 1 - ten: -9
   - ten: -10

-1 - 10: -11
 0 - 10: -10
 1 - 10: -9
   - 10: -10

minusOne - 10: -11
    zero - 10: -10
     one - 10: -9

minusOne - ten: -11
    zero - ten: -10
     one - ten: -9

(4 - 4) - 10:          -10 [works under mcs]
      0 - (5 * 2):     -10 [works under mcs]
      0 - (ten):       -10 [fails under mcs]
      0 - (ten * 2):   -20 [fails under mcs]
      0 - (ten * one): -10 [fails under mcs]

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