This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bugfix for array predecrement/preincrement


This patch fixed bug PR# 3096, PR#3965. 
The expand_increment function has bad increaction with INDIRECT_REF
attach with SAVE_EXRP child, I don't have any idea on how to fix this. So,
move SAVE_EXPR on ARRAY_REF down the tree workaround the problem. 

It passed libjava bootstrap and test regressive.

This is the addition test on this patch.

class TestArray
{
    static int [] b = new int[1];
    
    public static int getIndex ()
    {
	b = new int[1];
	b[0] = 10;
	return 0;
    }
    public static void main(String[] args) {
	b[0] = 1;
	System.out.println (b[getIndex ()]);
    }
}


Index: ChangeLog
===================================================================
RCS file: /home/nicholas/gc-works/gcc/cvsroot/gcc/gcc/java/ChangeLog,v
retrieving revision 1.2
diff -u -c -3 -p -r1.2 ChangeLog
*** ChangeLog	22 Sep 2001 07:34:46 -0000	1.2
--- ChangeLog	27 Sep 2001 07:13:27 -0000
***************
*** 1,3 ****
--- 1,10 ----
+ 2001-09-27  Tang Ching-Hui  <nicholas@cs.nthu.edu.tw>
+ 
+ 	* parse.y: (patch_array_ref): Remove SAVE_EXPR on ARRAY_REF.
+ 	(patch_assignment): Correctly extract the array base from the 
+ 	tree generate by build_java_arrayaccess.
+ 	* expr.c: call save_expr on array for correct evaluation order.
+ 
  2001-09-19  Alexandre Petit-Bianco  <apbianco@redhat.com>
  
  	* parse.h: (WFL_STRIP_BRACKET): Re-written using
Index: expr.c
===================================================================
RCS file: /home/nicholas/gc-works/gcc/cvsroot/gcc/gcc/java/expr.c,v
retrieving revision 1.2
diff -u -c -3 -p -r1.2 expr.c
*** expr.c	22 Sep 2001 07:34:48 -0000	1.2
--- expr.c	26 Sep 2001 20:39:02 -0000
*************** build_java_arrayaccess (array, type, ind
*** 799,804 ****
--- 799,810 ----
  	}
      }
    
+   /* The save_expr is for correct evaluation order.  It would be cleaner
+      to use force_evaluation_order (see comment there), but that is
+      difficult when we also have to deal with bounds checking. */
+   if (TREE_SIDE_EFFECTS (index))
+     throw = build (COMPOUND_EXPR, int_type_node, save_expr (array), throw);
+ 
    node = build1 (INDIRECT_REF, type, 
  		 fold (build (PLUS_EXPR, ptr_type_node, 
  			      java_check_reference (array, flag_check_references), 
Index: parse.y
===================================================================
RCS file: /home/nicholas/gc-works/gcc/cvsroot/gcc/gcc/java/parse.y,v
retrieving revision 1.2
diff -u -c -3 -p -r1.2 parse.y
*** parse.y	22 Sep 2001 07:34:49 -0000	1.2
--- parse.y	26 Sep 2001 20:36:29 -0000
*************** patch_assignment (node, wfl_op1, wfl_op2
*** 12943,12952 ****
            /* We can have a SAVE_EXPR here when doing String +=.  */
            if (TREE_CODE (op) == SAVE_EXPR)
              op = TREE_OPERAND (op, 0);
!           if (flag_bounds_check)
              base = TREE_OPERAND (TREE_OPERAND (op, 1), 0);
            else
              base = TREE_OPERAND (op, 0);
  	}
  
        /* Build the invocation of _Jv_CheckArrayStore */
--- 12943,12954 ----
            /* We can have a SAVE_EXPR here when doing String +=.  */
            if (TREE_CODE (op) == SAVE_EXPR)
              op = TREE_OPERAND (op, 0);
!           if (TREE_CODE (op) == COMPOUND_EXPR)
              base = TREE_OPERAND (TREE_OPERAND (op, 1), 0);
            else
              base = TREE_OPERAND (op, 0);
+ 	  if (TREE_CODE (base) == PLUS_EXPR)
+ 	    base = TREE_OPERAND (base, 0);
  	}
  
        /* Build the invocation of _Jv_CheckArrayStore */
*************** patch_array_ref (node)
*** 14590,14605 ****
        TREE_OPERAND (node, 1) = index;
      }
    else
!     {
!       /* The save_expr is for correct evaluation order.  It would be cleaner
! 	 to use force_evaluation_order (see comment there), but that is
! 	 difficult when we also have to deal with bounds checking. */
!       if (TREE_SIDE_EFFECTS (index))
! 	array = save_expr (array);
!       node = build_java_arrayaccess (array, array_type, index);
!       if (TREE_SIDE_EFFECTS (index))
! 	node = build (COMPOUND_EXPR, array_type, array, node);
!     }
    TREE_TYPE (node) = array_type;
    return node;
  }
--- 14592,14598 ----
        TREE_OPERAND (node, 1) = index;
      }
    else
!     node = build_java_arrayaccess (array, array_type, index);
    TREE_TYPE (node) = array_type;
    return node;
  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]