[tuples] start c_gimple_diagnostics_recursively conversion

Aldy Hernandez aldyh@redhat.com
Tue Jul 24 15:23:00 GMT 2007


> get_callee_fndecl should not be needed in GIMPLE.  When we are
> gimplifying we should set gimple_call_fn() to the right DECL (so we call
> get_callee_fndecl only once in gimplify_call_expr).

Ok, makes sense.

> > +	  if (fdecl)
> 
> This test should then become 'if (DECL_P (gimple_call_fn (g)))'

Actually, it should be 'if (TREE_CODE (fdecl) == FUNCTION_DECL)'.  See
patch.  We either have FUNCTION_DECL (when get_callee_fndecl returned
something), or we have the VAR_DECL (when we are calling a function
through a pointer).

Is the patch below ok?

	* tree.c (get_callee_fndecl): Revert previous change.
	* gimplify.c (gimplify_call_expr): Use result from
	get_callee_fndecl if available.
	* c-common.c (c_warn_unused_result): Do not use
	get_callee_fndecl.
	Add assertion.

Index: tree.c
===================================================================
--- tree.c	(revision 126860)
+++ tree.c	(working copy)
@@ -6373,10 +6373,9 @@ decl_type_context (tree decl)
   return NULL_TREE;
 }
 
-/* CALL is either a CALL_EXPR or the function to call (usually the
-   value of CALL_EXPR_FN in the original CALL_EXPR, or the CALL_FN in
-   a GIMPLE_CALL).  Return the declaration for the function called, or
-   NULL_TREE if the called function cannot be determined.  */
+/* CALL is a CALL_EXPR.  Return the declaration for the function
+   called, or NULL_TREE if the called function cannot be
+   determined.  */
 
 tree
 get_callee_fndecl (tree call)
@@ -6386,16 +6385,13 @@ get_callee_fndecl (tree call)
   if (call == error_mark_node)
     return call;
 
+  /* It's invalid to call this function with anything but a
+     CALL_EXPR.  */
+  gcc_assert (TREE_CODE (call) == CALL_EXPR);
+
   /* The first operand to the CALL is the address of the function
      called.  */
-  if (TREE_CODE (call) == CALL_EXPR)
-    addr = CALL_EXPR_FN (call);
-  else
-    {
-      /* If we don't have a CALL_EXPR, we must have the function
-	 itself already.  */
-      addr = call;
-    }
+  addr = CALL_EXPR_FN (call);
 
   STRIP_NOPS (addr);
 
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 126849)
+++ gimplify.c	(working copy)
@@ -2180,7 +2180,7 @@ gimplify_call_expr (tree *expr_p, gimple
 
   /* Now add the GIMPLE call to PRE_P.  If WANT_VALUE is set, we need
      to create the appropriate temporary for the call's LHS.  */
-  call = gimple_build_call_vec (CALL_EXPR_FN (*expr_p), args);
+  call = gimple_build_call_vec (fndecl ? fndecl : CALL_EXPR_FN (*expr_p), args);
   gimple_add (pre_p, call);
   if (want_value)
     {
Index: c-common.c
===================================================================
--- c-common.c	(revision 126860)
+++ c-common.c	(working copy)
@@ -6450,15 +6450,16 @@ c_warn_unused_result (gimple_seq seq)
 	  /* This is a naked call, as opposed to a GIMPLE_CALL with an
 	     LHS.  All calls whose value is ignored should be
 	     represented like this.  Look for the attribute.  */
-	  fdecl = get_callee_fndecl (gimple_call_fn (g));
-	  if (fdecl)
+	  fdecl = gimple_call_fn (g);
+	  if (TREE_CODE (fdecl) == FUNCTION_DECL)
 	    ftype = TREE_TYPE (fdecl);
 	  else
 	    {
-	      ftype = TREE_TYPE (gimple_call_fn (g));
+	      ftype = TREE_TYPE (fdecl);
 	      /* Look past pointer-to-function to the function type itself.  */
 	      ftype = TREE_TYPE (ftype);
 	    }
+	  gcc_assert (TREE_CODE (ftype) == FUNCTION_TYPE);
 
 	  if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype)))
 	    {



More information about the Gcc-patches mailing list