diff mbox

[RFC] Make called function type explicit, make function pointer type conversions useless

Message ID alpine.LNX.2.00.1104141759290.810@zhemvz.fhfr.qr
State New
Headers show

Commit Message

Richard Biener April 14, 2011, 4:05 p.m. UTC
On Thu, 14 Apr 2011, Eric Botcazou wrote:

> > I'm working on a fix along this line, it needs some tweaks elsewhere.
> 
> Indeed, here's what I needed to bootstrap on x86-64/Linux.
> 
> 
> 	* cfgexpand.c (expand_call_stmt): Rematerialize original function type.
> 	* config/i386/i386.c (ix86_expand_builtin): Use get_callee_fndecl.

I have the following, the gimple_call_chain check is to prevent
Ada bootstrap from failing.  It would be nice to eventually
expand calls from gimple and adjust calls.c to look only at
the function type, not the decl ...

That get_callee_fndecl strips all conversions might be a bug
anyway.

I suppose your patch is ok, maybe with simply not wrapping the NOP_EXPR
around builtins.

Richard.

Comments

Eric Botcazou April 14, 2011, 4:31 p.m. UTC | #1
> I have the following, the gimple_call_chain check is to prevent
> Ada bootstrap from failing.

On x86?

> I suppose your patch is ok, maybe with simply not wrapping the NOP_EXPR
> around builtins.

I can try that indeed...
Richard Biener April 15, 2011, 9:13 a.m. UTC | #2
On Thu, 14 Apr 2011, Eric Botcazou wrote:

> > I have the following, the gimple_call_chain check is to prevent
> > Ada bootstrap from failing.
> 
> On x86?

Yes, though maybe because I had get_callee_fndecl patched to not
strip conversions.

> > I suppose your patch is ok, maybe with simply not wrapping the NOP_EXPR
> > around builtins.
> 
> I can try that indeed...

Thanks for fixing this!

Richard.
diff mbox

Patch

Index: gcc/cfgexpand.c
===================================================================
--- gcc/cfgexpand.c     (revision 172429)
+++ gcc/cfgexpand.c     (working copy)
@@ -1841,11 +1841,28 @@  expand_call_stmt (gimple stmt)
   size_t i;
   bool builtin_p;
   tree decl;
+  tree fn;
 
   exp = build_vl_exp (CALL_EXPR, gimple_call_num_args (stmt) + 3);
 
-  CALL_EXPR_FN (exp) = gimple_call_fn (stmt);
+  fn = gimple_call_fn (stmt);
   decl = gimple_call_fndecl (stmt);
+  /* Restore the ABI relevant type for expansion.
+     ???  We should have a target hook that compares function signatures
+     for ABI compatibility.  */
+  if (TREE_TYPE (TREE_TYPE (fn)) != gimple_call_fntype (stmt)
+      /* ???  The static_chain target hook needs to be changed to
+         take a function type instead of a decl.  See
+        calls.c:prepare_call_address.  */
+      && !gimple_call_chain (stmt)
+      /* ???  Most builtins cannot be called indirectly.  */
+      && (!decl || !DECL_BUILT_IN (decl)))
+    {
+      fn = build1 (NOP_EXPR,
+                  build_pointer_type (gimple_call_fntype (stmt)), fn);
+      decl = NULL_TREE;
+    }
+  CALL_EXPR_FN (exp) = fn;
   builtin_p = decl && DECL_BUILT_IN (decl);
 
   TREE_TYPE (exp) = gimple_call_return_type (stmt);