[Mono-bugs] [Bug 78311][Maj] New - Dead code elimination breaks testcase involving Interlocked.Increment

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri May 5 20:09:57 EDT 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by horst.reiterer at mind-breeze.com.

http://bugzilla.ximian.com/show_bug.cgi?id=78311

--- shadow/78311	2006-05-05 20:09:57.000000000 -0400
+++ shadow/78311.tmp.3906	2006-05-05 20:09:57.000000000 -0400
@@ -0,0 +1,81 @@
+Bug#: 78311
+Product: Mono: Runtime
+Version: 1.1
+OS: other
+OS Details: Red Hat Enterprise Linux 4
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: JIT
+AssignedTo: lupus at ximian.com                            
+ReportedBy: horst.reiterer at mind-breeze.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Dead code elimination breaks testcase involving Interlocked.Increment
+
+The following testcase fails with dead code elimination turned on. The
+return value of Interlocked.Increment is incorrect. Without the
+optimization, the testcase can be executed successfully.
+
+using System;
+using System.Threading;
+
+public class Test
+{
+  public static void Main()
+  {
+    int test = 1;
+    int result = Interlocked.Increment(ref test);
+
+    if (result != 2) {
+      Console.WriteLine("Incorrect Increment result: " + result);
+    }
+  }
+}
+
+Steps to reproduce the problem:
+1. mono --optimize=deadce testcase.cs
+
+Actual Results:
+
+A return value of 1.
+
+Expected Results:
+
+A return value of 2.
+
+How often does this happen? 
+
+100 out of 100 times
+
+Additional Information:
+
+Comparing the generated assembly reveals that the dead code elimination
+pass removes the initialization of the local variable test. As a result,
+the initial value of 'test' is undefined and the result of
+Interlocked.Increment is thus equally undefined and incorrect.
+
+Dead code elimination DISABLED:
+
+ // Initialization of 'test'
+ 495:   c7 45 f0 00 00 00 00    movl   $0x0,0xfffffff0(%ebp)
+ 49c:   33 f6                   xor    %esi,%esi
+ // Assignment of immediate value '1'
+ 49e:   c7 45 f0 01 00 00 00    movl   $0x1,0xfffffff0(%ebp)
+ 4a5:   b8 01 00 00 00          mov    $0x1,%eax
+ 4aa:   8b f0                   mov    %eax,%esi
+ 4ac:   f0 0f c1 75 f0          lock xadd %esi,0xfffffff0(%ebp)
+ 4b1:   03 f0                   add    %eax,%esi
+ 4b3:   83 fe 02                cmp    $0x2,%esi
+
+Dead code elimination ENABLED:
+
+ 495:   b8 01 00 00 00          mov    $0x1,%eax
+ 49a:   8b f0                   mov    %eax,%esi
+ // Use of uninitialized local variable 'test'
+ 49c:   f0 0f c1 75 f0          lock xadd %esi,0xfffffff0(%ebp)
+ 4a1:   03 f0                   add    %eax,%esi
+ 4a3:   83 fe 02                cmp    $0x2,%esi


More information about the mono-bugs mailing list