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]

[PATCH] Fix parts of PR37046


During propagation of function addresses (ADDR_EXR <fndecl>) into the
function slot of a gimple call expression we fail to strip the ADDR_EXPR
which causes gimple_call_get_fndecl to return NULL.  This causes
the testcase below to fail even though CCP is able to enable the inlining
of foo ().

Diego, I expect there will be some more places we have to deal with
this change in canonicalization of calls to fndecls (we might want to
add some stmt checking for that, but as I know the inliner messes this
up as well I'll wait until after that is fixed).  Maybe you have
some opinion on these kind of fixes? ...

Bootstrapped and tested on x86_64-unknown-linux-gnu - I'll wait for
some comments before committing.

Thanks,
Richard.

2008-08-08  Richard Guenther  <rguenther@suse.de>

	PR middle-end/37046
	* tree-ssa-copy.c (replace_exp_1): Handle propagating
	function addresses into call statement function slots specially.

	* gcc.dg/tree-ssa/inline-2.c: New testcase.

Index: gcc/tree-ssa-copy.c
===================================================================
*** gcc/tree-ssa-copy.c	(revision 138834)
--- gcc/tree-ssa-copy.c	(working copy)
*************** replace_exp_1 (use_operand_p op_p, tree
*** 370,376 ****
        SET_USE (op_p, val);
      }
    else
!     SET_USE (op_p, unsave_expr_now (val));
  }
  
  
--- 370,386 ----
        SET_USE (op_p, val);
      }
    else
!     {
!       /* If the use statement is a call and we propagate into the
! 	 function operand and the value we propagate is
! 	 the address of a function declaration strip the ADDR_EXPR.  */
!       if (TREE_CODE (val) == ADDR_EXPR
! 	  && TREE_CODE (TREE_OPERAND (val, 0)) == FUNCTION_DECL
! 	  && gimple_code (USE_STMT (op_p)) == GIMPLE_CALL
! 	  && gimple_call_fn_ptr (USE_STMT (op_p)) == op_p->use)
! 	val = TREE_OPERAND (val, 0);
!       SET_USE (op_p, unsave_expr_now (val));
!     }
  }
  
  
Index: gcc/testsuite/gcc.dg/tree-ssa/inline-2.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/inline-2.c	(revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/inline-2.c	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ /* { dg-do link } */
+ /* { dg-options "-O" } */
+ 
+ /* When optimized we expect the call to foo () in bar to be inlined
+    and the call to link_error optimized away.  */
+ 
+ extern void link_error (void);
+ int __attribute__((always_inline)) foo(void) { return 0; }
+ 
+ int main()
+ {
+   int (*fn)(void) = foo;
+   if (fn())
+     link_error ();
+   return 0;
+ }


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