http://bugzilla.novell.com/show_bug.cgi?id=610126
http://bugzilla.novell.com/show_bug.cgi?id=610126#c0 Summary: Different IL code for bitwise AND in and out of an ('eta' expanded) if statement Classification: Mono Product: Mono: Compilers Version: 2.4.x Platform: 32bit OS/Version: WinMobil Status: NEW Severity: Normal Priority: P5 - None Component: C# AssignedTo: [email protected] ReportedBy: [email protected] QAContact: [email protected] Found By: --- Blocker: --- User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.10pre) Gecko/20100410 Ubuntu/9.10 (karmic) Firefox/3.5.9 Bug shows up when running [g]mcs executables on Windows Mobile. Comparing the bitwise AND of two long values to 0L "((a & b) == 0L)" results in generated IL code that that performs the AND then a conditional branch (brtrue) . It looks like the CIL specification has the argument to "brtrue" of type 'I' (not 'I8'), so I'm not sure if it's a subtle mis-optimization in GMCS. Microsoft CSC generates code that uses temporary variables for all subexpressions and return values, so it doesn't suffer from this problem. Here's a small test case. The output file allows me to easily test on Windows Mobile. //------------------------------------------------------------ using System; using System.IO; public static class Test{ public static void Main(String[] args){ StreamWriter file = new StreamWriter(new FileStream("test.txt", FileMode.Create)); file.WriteLine(" Test 1: "+test1(15,15)); file.WriteLine(" Test 2: "+test2(15,15)); file.Close(); } static bool test1(long a, long b){ if((a & b) == 0L)return true; return false; } static bool test2(long a, long b){ return ((a & b) == 0L); } } //------------------------------------------------------- For the first method (test1), GMCS generates code (summarized) as follows: ldarg.0 ldarg.1 and brtrue RET_FALSE ldc.i4.1 ret RET_FALSE: ldc.i4.0 ret And for the second (test2), it generates (correct) code: ldarg.0 ldarg.1 and ldc.i4.0 conv.i8 ceq ret Both methods should obviously return false when called with identical values for 'a' and 'b', but the first method returns true. Reproducible: Always Steps to Reproduce: 1. Compile the Test class using GMCS 2. Patch the executable to run on Windows Mobile 3. Transfer to a Windows Mobile device and run 4. Inspect the created file "test.txt" Actual Results: Test 1: True Test 2: False Expected Results: Test 1: False Test 2: False -- 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. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
