[Mono-bugs] [Bug 24546] New - Jit: Incorrect addition code

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
11 May 2002 00:18:05 -0000


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 dihlewis@yahoo.co.uk.

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

--- shadow/24546	Fri May 10 20:18:05 2002
+++ shadow/24546.tmp.23187	Fri May 10 20:18:05 2002
@@ -0,0 +1,53 @@
+Bug#: 24546
+Product: Mono/Runtime
+Version: unspecified
+OS: other
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: dihlewis@yahoo.co.uk               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Jit: Incorrect addition code
+
+Sorry I couldn't find a more specific example, this bug seems a little complex:
+
+
+using System;
+ 
+class Test {
+        public static void Main () {
+                int [] n = new int [1];
+                int b = 16;
+ 
+                n [0] = 100 + (1 << (16 - b));
+                Console.WriteLine (n [0]);
+        }
+}
+
+
+Obviously the value of n [0] should be 101, but mono arrives at 1 instead.
+
+More clues:
+
+* The array reference is necessary for the error. Assigning to a regular
+variable doesn't work.
+
+* Rearranging the addition results in correct operation - it seems this
+addition operator is not entirely commutative. ie this works:
+
+  n [0] = (1 << (16  b)) + 100;
+
+* The shift operator also appears to be implicated.
+
+The tree looks correct, but I'm afraid I'm way too tired to peruse the
+generated x86...
+
+  (STIND_I4 (LDELEMA (LDIND_I4 ADDR_L[R1]) CONST_I4[0]) (ADD CONST_I4[100]
+(SHL CONST_I4[1] (SUB CONST_I4[16] (LDIND_I4 ADDR_L[R2])))))