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]

[tuples] make most C++ testcase work


Hi folks.

The following patch pretty much converts the rest of the C++ gimplifier.
Most tests now pass the cc1plus stage.  

I have two real compilation failures that need to be addressed and I'll
be punting those to Diego, as one is a CFG problem, and the other one is
an assert he coded, that I'm not sure how to handle.

Most changes here are the usual brain-dead type, with the following
exceptions...

- cp_genericize would refuse to gimplify a cloned function, because it
  had already been gimplied.  However, we need to set the gimple_body()
  pointer map accordingly so gimple_body() returns the body of the
  original cloned function.  Fixed.

- With the new type checking code, the gimplifier will sometimes
  attempt to build erroneous tuples and would die with asserts all over
  the place.  I've fixed the places I've triggered so far, making the
  gimplifier return GS_ERROR without dying first.

- gimple_call_return_type should handle methods.  Fixed.

- I've fixed gimplify_statement_list to handle cases where
  voidify_wrapper() actually returns something.

Yay, yay... The C++ front end was not as painful as I thought it would
be.

I'm committing this to the branch, and will follow up with Diego (ok, I
will beg) to work on the CGG and that other failure.  After which... I
will start torturing cc1plus with Diego's sandbox of .ii test files.

Aldy

	* cp/cp-gimplify.c (gimplify_cp_loop): Tuplify.
	(gimplify_for_stmt): Same.
	(gimplify_switch_stmt): Same.
	(cp_gimplify_expr): [FOR_STMT]: Do not call gimplify_for_stmt.  Return
	GS_OK.
	[WHILE_STMT]: Return GS_OK.
	[SWITCH_STMT]: Same.
	[CONTINUE_STMT]: Same.
	[BREAK_STMT]: Same.
	(cp_genericize): Set gimple_body() of cloned functions when needed.
	* gimplify.c (get_tmp_var_for): Remove reference to IS_FORMAL in
	opening comment.
	(gimplify_return_expr): Return GS_ERROR if we have errored.
	(gimplify_statement_list): Handle case where voidify_wrapper returns a
	temporary.
	(gimplify_call_expr): Return gracefully on error.
	(gimplify_cond_expr): Same.
	* gimple.h (gimple_call_return_type): Do not error on methods.

Index: cp/cp-gimplify.c
===================================================================
--- cp/cp-gimplify.c	(revision 129726)
+++ cp/cp-gimplify.c	(working copy)
@@ -214,6 +214,7 @@ gimplify_cp_loop (tree cond, tree body, 
       if (cond_is_first)
 	{
 	  t = build_bc_goto (bc_break);
+	  SET_EXPR_LOCATION (t, stmt_locus);
 	  append_to_statement_list (t, &stmt_list);
 	}
     }
@@ -233,9 +234,6 @@ gimplify_cp_loop (tree cond, tree body, 
 	{
 	  t = build_bc_goto (bc_break);
 	  exit = fold_build3 (COND_EXPR, void_type_node, cond, exit, t);
-	  /* FIXME tuples
-	  gimplify_stmt (&exit);
-	  */
 
 	  if (cond_is_first)
 	    {
@@ -246,27 +244,36 @@ gimplify_cp_loop (tree cond, tree body, 
 		}
 	      else
 		t = build_bc_goto (bc_continue);
+	      SET_EXPR_LOCATION (t, stmt_locus);
 	      append_to_statement_list (t, &stmt_list);
 	    }
 	}
     }
 
-  /* FIXME tuples
-  gimplify_stmt (&body);
-  gimplify_stmt (&incr);
-  */
-
   body = finish_bc_block (bc_continue, cont_block, body);
 
+  /* Annotate the new statements individually because annotate_all_with_locus
+     only works on gimple sequences.  */
+
+  if (top && CAN_HAVE_LOCATION_P (top))
+    SET_EXPR_LOCATION (top, stmt_locus);
   append_to_statement_list (top, &stmt_list);
+
+  if (body && CAN_HAVE_LOCATION_P (body))
+    SET_EXPR_LOCATION (body, stmt_locus);
   append_to_statement_list (body, &stmt_list);
+
+  if (incr && CAN_HAVE_LOCATION_P (incr))
+    SET_EXPR_LOCATION (incr, stmt_locus);
   append_to_statement_list (incr, &stmt_list);
+
+  if (entry && CAN_HAVE_LOCATION_P (entry))
+    SET_EXPR_LOCATION (entry, stmt_locus);
   append_to_statement_list (entry, &stmt_list);
-  append_to_statement_list (exit, &stmt_list);
 
-  /* FIXME tuples
-  annotate_all_with_locus (&stmt_list, stmt_locus);
-  */
+  if (exit && CAN_HAVE_LOCATION_P (exit))
+    SET_EXPR_LOCATION (exit, stmt_locus);
+  append_to_statement_list (exit, &stmt_list);
 
   return finish_bc_block (bc_break, break_block, stmt_list);
 }
@@ -274,10 +281,8 @@ gimplify_cp_loop (tree cond, tree body, 
 /* Gimplify a FOR_STMT node.  Move the stuff in the for-init-stmt into the
    prequeue and hand off to gimplify_cp_loop.  */
 
-/* FIXME tuples */
-#if 0
 static void
-gimplify_for_stmt (tree *stmt_p, tree *pre_p)
+gimplify_for_stmt (tree *stmt_p, gimple_seq pre_p)
 {
   tree stmt = *stmt_p;
 
@@ -287,7 +292,6 @@ gimplify_for_stmt (tree *stmt_p, tree *p
   *stmt_p = gimplify_cp_loop (FOR_COND (stmt), FOR_BODY (stmt),
 			      FOR_EXPR (stmt), 1);
 }
-#endif
 
 /* Gimplify a WHILE_STMT node.  */
 
@@ -327,9 +331,6 @@ gimplify_switch_stmt (tree *stmt_p)
   *stmt_p = build3 (SWITCH_EXPR, SWITCH_STMT_TYPE (stmt),
 		    SWITCH_STMT_COND (stmt), body, NULL_TREE);
   SET_EXPR_LOCATION (*stmt_p, stmt_locus);
-  /* FIXME tuples
-  gimplify_stmt (stmt_p);
-  */
 
   *stmt_p = finish_bc_block (bc_break, break_block, *stmt_p);
 }
@@ -547,25 +548,23 @@ cp_gimplify_expr (tree *expr_p, gimple_s
       break;
 
     case FOR_STMT:
-      /* FIXME tuples
       gimplify_for_stmt (expr_p, pre_p);
-      */
-      ret = GS_ALL_DONE;
+      ret = GS_OK;
       break;
 
     case WHILE_STMT:
       gimplify_while_stmt (expr_p);
-      ret = GS_ALL_DONE;
+      ret = GS_OK;
       break;
 
     case DO_STMT:
       gimplify_do_stmt (expr_p);
-      ret = GS_ALL_DONE;
+      ret = GS_OK;
       break;
 
     case SWITCH_STMT:
       gimplify_switch_stmt (expr_p);
-      ret = GS_ALL_DONE;
+      ret = GS_OK;
       break;
 
     case OMP_FOR:
@@ -574,12 +573,12 @@ cp_gimplify_expr (tree *expr_p, gimple_s
 
     case CONTINUE_STMT:
       *expr_p = build_bc_goto (bc_continue);
-      ret = GS_ALL_DONE;
+      ret = GS_OK;
       break;
 
     case BREAK_STMT:
       *expr_p = build_bc_goto (bc_break);
-      ret = GS_ALL_DONE;
+      ret = GS_OK;
       break;
 
     case EXPR_STMT:
@@ -760,9 +759,17 @@ cp_genericize (tree fndecl)
       relayout_decl (t);
     }
 
-  /* If we're a clone, the body is already GIMPLE.  */
+  /* If we're a clone, the body is already GIMPLE.  Find the original
+     body, and set the gimple body for this function accordingly.  */
   if (DECL_CLONED_FUNCTION_P (fndecl))
-    return;
+    {
+      tree orig = DECL_CLONED_FUNCTION (fndecl);
+      gimple_seq seq = gimple_body (orig);
+
+      gimple_set_body (fndecl, seq);
+      DECL_SAVED_TREE (fndecl) = NULL_TREE;
+      return;
+    }
 
   /* We do want to see every occurrence of the parms, so we can't just use
      walk_tree's hash functionality.  */
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 129726)
+++ gimplify.c	(working copy)
@@ -621,10 +621,7 @@ get_initialized_tmp_var (tree val, gimpl
 }
 
 /* Create a temporary variable to be used as the LHS of the given GIMPLE
-   statement STMT. STMT must be GIMPLE_ASSIGN or GIMPLE_CALL.  If IS_FORMAL is
-   true, try to return a temporary from the formal temporaries table
-   (which will attempt to return the same temporary created for a
-   previous statement identical to STMT.  */
+   statement STMT. STMT must be GIMPLE_ASSIGN or GIMPLE_CALL.  */
 
 static tree
 get_tmp_var_for (gimple stmt)
@@ -1105,6 +1102,9 @@ gimplify_return_expr (tree stmt, gimple_
   tree ret_expr = TREE_OPERAND (stmt, 0);
   tree result_decl, result;
 
+  if (ret_expr == error_mark_node)
+    return GS_ERROR;
+
   if (!ret_expr
       || TREE_CODE (ret_expr) == RESULT_DECL
       || ret_expr == error_mark_node)
@@ -1304,13 +1304,8 @@ gimplify_statement_list (tree *expr_p, g
 
   if (temp)
     {
-      /* FIXME tuples.  Not clear how this should be handled.  */
-      gcc_unreachable ();
-#if 0
-      append_to_statement_list (*expr_p, pre_p);
       *expr_p = temp;
       return GS_OK;
-#endif
     }
 
   return GS_ALL_DONE;
@@ -2255,6 +2250,11 @@ gimplify_call_expr (tree *expr_p, gimple
 	  return GS_OK;
 	}
     }
+  else
+    {
+      *expr_p = NULL_TREE;
+      return GS_ERROR;
+    }
 
   /* If the function is "const" or "pure", then clear
      TREE_SIDE_EFFECTS on its decl.  This allows us to eliminate
@@ -2666,6 +2666,8 @@ gimplify_cond_expr (tree *expr_p, gimple
   /* Gimplify condition.  */
   ret = gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, NULL, is_gimple_condexpr,
 		       fb_rvalue);
+  if (ret == GS_ERROR)
+    return GS_ERROR;
   gcc_assert (TREE_OPERAND (expr, 0) != NULL_TREE);
 
   gimple_push_condition ();
Index: gimple.h
===================================================================
--- gimple.h	(revision 129675)
+++ gimple.h	(working copy)
@@ -1067,7 +1067,8 @@ gimple_call_return_type (const_gimple gs
   if (TREE_CODE (type) == POINTER_TYPE)
     type = TREE_TYPE (type);
 
-  gcc_assert (TREE_CODE (type) == FUNCTION_TYPE);
+  gcc_assert (TREE_CODE (type) == FUNCTION_TYPE
+	      || TREE_CODE (type) == METHOD_TYPE);
 
   /* The type returned by a FUNCTION_DECL is the type of its
      function type.  */


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