[Mono-bugs] [Bug 686433] New: (0 - x) == x according to dmcs. bad constant folding.
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Sat Apr 9 00:42:45 EDT 2011
https://bugzilla.novell.com/show_bug.cgi?id=686433
https://bugzilla.novell.com/show_bug.cgi?id=686433#c0
Summary: (0 - x) == x according to dmcs. bad constant folding.
Classification: Mono
Product: Mono: Compilers
Version: 2.10.x
Platform: Macintosh
OS/Version: Mac OS X 10.6
Status: NEW
Severity: Critical
Priority: P5 - None
Component: C#
AssignedTo: msafar at novell.com
ReportedBy: brian at sooloos.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
Blocker: ---
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7)
AppleWebKit/534.28 (KHTML, like Gecko) Chrome/12.0.725.0 Safari/534.28
I could not believe this when I saw it...
it looks like bad constant folding in the compiler. (0 - x) is being
transformed into (x) when C# is compiled to IL. This is with 2.10.1 on macos x
10.6.7.
brian at brianmbp ~ $ cat t.cs
using System;
class Foo {
public static void Main(string[] args) {
int foo = 32 * 1024;
Console.WriteLine(" - foo = {0}", - foo);
Console.WriteLine("0 - foo = {0}", 0 - foo);
}
}
brian at brianmbp ~ $ dmcs t.cs && mono t.exe
- foo = -32768
0 - foo = 32768
brian at brianmbp ~ $ monodis t.exe
assembly extern mscorlib
{
.ver 4:0:0:0
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
}
assembly 't'
{
.custom instance void class
[mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::'.ctor'()
= (
01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78 // ....T..WrapNonEx
63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 ) // ceptionThrows.
.hash algorithm 0x00008004
.ver 0:0:0:0
}
module t.exe // GUID = {E0608D43-1541-4796-AA7C-B49D16107C31}
.class private auto ansi beforefieldinit Foo
extends [mscorlib]System.Object
{
// method line 1
.method public hidebysig specialname rtspecialname
instance default void '.ctor' () cil managed
{
// Method begins at RVA 0x20ec
// Code size 7 (0x7)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void object::'.ctor'()
IL_0006: ret
} // end of method Foo::.ctor
// method line 2
.method public static hidebysig
default void Main (string[] args) cil managed
{
// Method begins at RVA 0x20f4
.entrypoint
// Code size 40 (0x28)
.maxstack 4
.locals init (
int32 V_0)
IL_0000: ldc.i4 32768
IL_0005: stloc.0
IL_0006: ldstr " - foo = {0}"
IL_000b: ldloc.0
IL_000c: neg
IL_000d: box [mscorlib]System.Int32
IL_0012: call void class [mscorlib]System.Console::WriteLine(string,
object)
IL_0017: ldstr "0 - foo = {0}"
IL_001c: ldloc.0
IL_001d: box [mscorlib]System.Int32
IL_0022: call void class [mscorlib]System.Console::WriteLine(string,
object)
IL_0027: ret
} // end of method Foo::Main
} // end of class Foo
Reproducible: Always
--
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