re PR java/3096 (GCJ does not increment)
authorTang Ching-Hui <nicholas@cs.nthu.edu.tw>
Sun, 2 Dec 2001 10:44:54 +0000 (18:44 +0800)
committerBryce McKinlay <bryce@gcc.gnu.org>
Sun, 2 Dec 2001 10:44:54 +0000 (10:44 +0000)
2001-12-02  Tang Ching-Hui  <nicholas@cs.nthu.edu.tw>
    Alexandre Petit-Bianco  <apbianco@redhat.com>

* expr.c: call save_expr on array for correct evaluation order,
modified comment, fixed indentation.
* parse.y: (patch_assignment): Correctly extract the array base
from the tree generate by build_java_arrayaccess, added comments.
(patch_array_ref): Remove SAVE_EXPR on ARRAY_REF.
Fixes PR java/3096, PR java/3803, PR java/3965.

Co-Authored-By: Alexandre Petit-Bianco <apbianco@redhat.com>
From-SVN: r47525

gcc/java/ChangeLog
gcc/java/expr.c
gcc/java/parse.y

index 1c0f009f8c0bf4cd492e248b385339615e0450ec..a7d9bc8de0437966bdff56fcb29f9baeaf38a747 100644 (file)
@@ -1,3 +1,13 @@
+2001-12-02  Tang Ching-Hui  <nicholas@cs.nthu.edu.tw>
+           Alexandre Petit-Bianco  <apbianco@redhat.com>
+
+       * expr.c: call save_expr on array for correct evaluation order, 
+       modified comment, fixed indentation.
+       * parse.y: (patch_assignment): Correctly extract the array base
+       from the tree generate by build_java_arrayaccess, added comments.
+       (patch_array_ref): Remove SAVE_EXPR on ARRAY_REF.
+       Fixes PR java/3096, PR java/3803, PR java/3965.
+
 2001-12-01  Neil Booth  <neil@daikokuya.demon.co.uk>
 
        * expr.c (expand_byte_code): Remove trailing periods from messages.
index 182d247f8903a476996be5cc91c3d445765eea3a..0d3c61d169aff83a83917d7e23a7546414903ad7 100644 (file)
@@ -798,14 +798,21 @@ build_java_arrayaccess (array, type, index)
          TREE_SIDE_EFFECTS( throw ) = 1;
        }
     }
-  
+
+  /* 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. The SAVE_EXPR is not necessary to do that when we're
+     not checking for array bounds. */
+  if (TREE_SIDE_EFFECTS (index) && throw)
+    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), 
+                             java_check_reference (array,
+                                                   flag_check_references), 
                              (throw ? build (COMPOUND_EXPR, int_type_node, 
-                                             throw, arith )
-                                    : arith))));
-  
+                                             throw, arith ) : arith))));
   return node;
 }
 
index 3b9900dff6f60deec3d70271918332359a641828..f63faa346b761534b651b7e28b2ecd198e0df00a 100644 (file)
@@ -12940,10 +12940,13 @@ patch_assignment (node, wfl_op1)
           /* 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);
+         /* We can have a COMPOUND_EXPR here when doing bounds check. */
+         if (TREE_CODE (op) == COMPOUND_EXPR)
+           op = TREE_OPERAND (op, 1);
+         base = TREE_OPERAND (op, 0);
+         /* Strip the last PLUS_EXPR to obtain the base. */
+         if (TREE_CODE (base) == PLUS_EXPR)
+           base = TREE_OPERAND (base, 0);
        }
 
       /* Build the invocation of _Jv_CheckArrayStore */
@@ -14592,16 +14595,7 @@ patch_array_ref (node)
       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);
-    }
+    node = build_java_arrayaccess (array, array_type, index);
   TREE_TYPE (node) = array_type;
   return node;
 }