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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fix 23714


The problem here is that at rtl expansion time we need arrays to
be in memory, so that we can emit pointer arithmetic on them.

But we'd very much prefer to have the array *not* be addressable 
througout the tree optimization passes.  One, having the array be
addressable means that SRA would no longer be able to operate on
it.  Two, I'm pretty sure that would mean that it would alias more
things; didn't actually test that.

The testcase is technically invalid, but we shouldn't ICE no
matter what.


r~


        PR 23714
        * tree-cfg.c (mark_array_ref_addressable_1): New.
        (mark_array_ref_addressable): New.
        * tree-flow.h (mark_array_ref_addressable): Declare.
        * tree-optimize.c (execute_cleanup_cfg_post_optimizing): Use it.

Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.221
diff -u -p -d -r2.221 tree-cfg.c
--- tree-cfg.c	13 Sep 2005 07:33:49 -0000	2.221
+++ tree-cfg.c	5 Oct 2005 23:57:54 -0000
@@ -421,6 +421,39 @@ fold_cond_expr_cond (void)
     }
 }
 
+/* Mark the array of any remaining ARRAY_REFs as addressable.  */
+
+static tree
+mark_array_ref_addressable_1 (tree *tp, int *walk_subtrees,
+			      void *data ATTRIBUTE_UNUSED)
+{
+  tree t = *tp;
+
+  if (DECL_P (t) || TYPE_P (t))
+    *walk_subtrees = 0;
+  else if (TREE_CODE (t) == ARRAY_REF)
+    {
+      tree base = get_base_address (TREE_OPERAND (t, 0));
+      if (base && DECL_P (base))
+	TREE_ADDRESSABLE (base) = 1;
+    }
+
+  return NULL_TREE;
+}
+
+void
+mark_array_ref_addressable (void)
+{
+  basic_block bb;
+  block_stmt_iterator i;
+
+  FOR_EACH_BB (bb)
+    {
+      for (i = bsi_start (bb); !bsi_end_p(i); bsi_next(&i))
+	walk_tree (bsi_stmt_ptr (i), mark_array_ref_addressable_1, NULL, NULL);
+    }
+}
+
 /* Join all the blocks in the flowgraph.  */
 
 static void
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-flow.h,v
retrieving revision 2.136
diff -u -p -d -r2.136 tree-flow.h
--- tree-flow.h	22 Sep 2005 00:42:28 -0000	2.136
+++ tree-flow.h	5 Oct 2005 23:57:54 -0000
@@ -556,6 +556,7 @@ extern tree gimplify_build3 (block_stmt_
 			     tree, tree, tree, tree);
 extern void init_empty_tree_cfg (void);
 extern void fold_cond_expr_cond (void);
+extern void mark_array_ref_addressable (void);
 extern void replace_uses_by (tree, tree);
 extern void start_recording_case_labels (void);
 extern void end_recording_case_labels (void);
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 2.123
diff -u -p -d -r2.123 tree-optimize.c
--- tree-optimize.c	24 Sep 2005 12:43:30 -0000	2.123
+++ tree-optimize.c	5 Oct 2005 23:57:54 -0000
@@ -133,6 +133,7 @@ static void 
 execute_cleanup_cfg_post_optimizing (void)
 {
   fold_cond_expr_cond ();
+  mark_array_ref_addressable ();
   cleanup_tree_cfg ();
   cleanup_dead_labels ();
   group_case_labels ();
Index: testsuite/g++.dg/opt/pr23714.C
===================================================================
RCS file: testsuite/g++.dg/opt/pr23714.C
diff -N testsuite/g++.dg/opt/pr23714.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/g++.dg/opt/pr23714.C	6 Oct 2005 00:01:02 -0000
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// { dg-options "-O2 -fnon-call-exceptions" }
+
+void run (void) {
+  float stack[1];
+  float *sp = stack;
+  try
+  {
+    float value2 = ((float) *(--sp));
+    float value1 = ((float) *(--sp));
+    *(sp++) = (value1 - value2);
+  }
+  catch (int *ex)
+  {
+  }
+}


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