disp_offset was always added to displacement returned by
frame_local_offset() which is incorrect because when local expression
is not an argument then its offset is negative and therefore
disp_offset should be subtracted.

This bug led to incorrect compilation of this code:

    long x = 10;
    long y = 20;
    long result = (10 + x) + (20 + y);

Signed-off-by: Tomek Grabiec <[email protected]>
---
 arch/x86/insn-selector_32.brg            |    9 +++++++--
 regression/jamvm/LongArithmeticTest.java |    9 +++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg
index 61430a0..9c41511 100644
--- a/arch/x86/insn-selector_32.brg
+++ b/arch/x86/insn-selector_32.brg
@@ -1168,11 +1168,16 @@ static void __binop_reg_local(struct _MBState *state, 
struct basic_block *bb,
 {
        struct var_info *frame_ptr;
        struct expression *expr;
-       unsigned long disp;
+       long disp;
 
        expr = to_expr(tree);
        disp = frame_local_offset(bb->b_parent->method, 
to_expr(expr->binary_right));
-       disp += disp_offset;
+       if (disp < 0)
+               /* local stack slot, decreasing offset values */
+               disp -= disp_offset;
+       else
+               /* method argument slot, increasing offset values */
+               disp += disp_offset;
 
        frame_ptr = bb->b_parent->frame_ptr;
 
diff --git a/regression/jamvm/LongArithmeticTest.java 
b/regression/jamvm/LongArithmeticTest.java
index 3675f60..30d9246 100644
--- a/regression/jamvm/LongArithmeticTest.java
+++ b/regression/jamvm/LongArithmeticTest.java
@@ -226,6 +226,14 @@ public class LongArithmeticTest extends TestCase {
         return value += 2;
     }
 
+    public static void testLongAdditionLocalSlot() {
+        long x = 0x1a;
+        long y = 0x0d;
+        long result = (0x1f + x) + (0x11 + y);
+
+        assertEquals(0x57, result);
+    }
+
     public static void main(String[] args) {
         testLongAddition();
         testLongAdditionOverflow();
@@ -250,6 +258,7 @@ public class LongArithmeticTest extends TestCase {
         testLongBitwiseAnd();
         testLongBitwiseExclusiveOr();
         testLongIncrementLocalByConstant();
+        testLongAdditionLocalSlot();
 
         Runtime.getRuntime().halt(retval);
     }
-- 
1.6.0.6


------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to