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 21894


We lost track of the correct value for val_only while processing a
component_ref.  This caused us to not hoist a reference to FRAME to
a temporary.

The setting of walk_subtrees is merely an optimization.  We (already)
set this in the case we do need to recurse.  This setting should 
have already been there, as it is in convert_nonlocal_reference.
Somehow, this line got lost here in convert_local_reference...


r~


        * tree-nested.c (convert_local_reference): Save and restore val_only
        around component_ref and friends.  Clear walk_subtrees by default.

Index: tree-nested.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-nested.c,v
retrieving revision 2.28
diff -u -p -d -r2.28 tree-nested.c
--- tree-nested.c	25 Jun 2005 02:01:28 -0000	2.28
+++ tree-nested.c	7 Aug 2005 18:57:22 -0000
@@ -950,7 +950,9 @@ convert_local_reference (tree *tp, int *
   struct walk_stmt_info *wi = data;
   struct nesting_info *info = wi->info;
   tree t = *tp, field, x;
+  bool save_val_only;
 
+  *walk_subtrees = 0;
   switch (TREE_CODE (t))
     {
     case VAR_DECL:
@@ -989,34 +991,31 @@ convert_local_reference (tree *tp, int *
       break;
 
     case ADDR_EXPR:
-      {
-	bool save_val_only = wi->val_only;
-
-	wi->val_only = false;
-	wi->is_lhs = false;
-	wi->changed = false;
-	walk_tree (&TREE_OPERAND (t, 0), convert_local_reference, wi, NULL);
-	wi->val_only = save_val_only;
+      save_val_only = wi->val_only;
+      wi->val_only = false;
+      wi->is_lhs = false;
+      wi->changed = false;
+      walk_tree (&TREE_OPERAND (t, 0), convert_local_reference, wi, NULL);
+      wi->val_only = save_val_only;
 
-	/* If we converted anything ... */
-	if (wi->changed)
-	  {
-	    tree save_context;
+      /* If we converted anything ... */
+      if (wi->changed)
+	{
+	  tree save_context;
 
-	    /* Then the frame decl is now addressable.  */
-	    TREE_ADDRESSABLE (info->frame_decl) = 1;
+	  /* Then the frame decl is now addressable.  */
+	  TREE_ADDRESSABLE (info->frame_decl) = 1;
 	    
-	    save_context = current_function_decl;
-	    current_function_decl = info->context;
-	    recompute_tree_invarant_for_addr_expr (t);
-	    current_function_decl = save_context;
+	  save_context = current_function_decl;
+	  current_function_decl = info->context;
+	  recompute_tree_invarant_for_addr_expr (t);
+	  current_function_decl = save_context;
 
-	    /* If we are in a context where we only accept values, then
-	       compute the address into a temporary.  */
-	    if (save_val_only)
-	      *tp = tsi_gimplify_val (wi->info, t, &wi->tsi);
-	  }
-      }
+	  /* If we are in a context where we only accept values, then
+	     compute the address into a temporary.  */
+	  if (save_val_only)
+	    *tp = tsi_gimplify_val (wi->info, t, &wi->tsi);
+	}
       break;
 
     case REALPART_EXPR:
@@ -1028,6 +1027,7 @@ convert_local_reference (tree *tp, int *
       /* Go down this entire nest and just look at the final prefix and
 	 anything that describes the references.  Otherwise, we lose track
 	 of whether a NOP_EXPR or VIEW_CONVERT_EXPR needs a simple value.  */
+      save_val_only = wi->val_only;
       wi->val_only = true;
       wi->is_lhs = false;
       for (; handled_component_p (t); tp = &TREE_OPERAND (t, 0), t = *tp)
@@ -1055,6 +1055,7 @@ convert_local_reference (tree *tp, int *
 	}
       wi->val_only = false;
       walk_tree (tp, convert_local_reference, wi, NULL);
+      wi->val_only = save_val_only;
       break;
 
     default:
Index: testsuite/gcc.c-torture/compile/nested-2.c
===================================================================
RCS file: testsuite/gcc.c-torture/compile/nested-2.c
diff -N testsuite/gcc.c-torture/compile/nested-2.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/compile/nested-2.c	7 Aug 2005 18:57:22 -0000
@@ -0,0 +1,16 @@
+/* PR 21105 */
+
+void
+CheckFile ()
+{
+  char tagname[10];
+  char *a = tagname;
+
+  int validate ()
+  {
+    return (a == tagname + 4);
+  }
+
+  if (a == tagname)
+    validate ();
+}


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