[patch] Extend return by invisible reference mechanism

Richard Guenther richard.guenther@gmail.com
Thu Apr 8 09:56:00 GMT 2010


On Wed, Apr 7, 2010 at 5:34 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> in http://gcc.gnu.org/ml/gcc-patches/2006-06/msg01330.html Olivier submitted a
> patch to make it possible to force return by invisible reference, by setting
> DECL_BY_REFERENCE on the DECL_RESULT of the called function.  This works fine
> for direct calls, but there is no DECL_RESULT at hand for indirect calls.
>
> As we would need to extend this mechanism to indirect calls, I'm proposing to
> replace it with a flag on the FUNCTION_TYPE instead, namely TREE_ADDRESSABLE.
> This is modelled on the regular way of setting return by invisible reference,
> which is to set TREE_ADDRESSABLE on the return TYPE of the FUNCTION_TYPE.  As
> explained by Olivier, setting TREE_ADDRESSABLE on the return TYPE has other
> consequences that we don't necessarily want in Ada, hence this weaker form.
>
> Tested on x86_64-suse-linux (in conjunction with the associated gigi patch).
>
> The calls.c change is actually a no-op: if you pass a FUNCTION_DECL as fntype
> to aggregate_value_p, it will just reset fntype to its TREE_TYPE.

Well, fndecl is needed for the DECL_RESULT check and ...

> The gimplify.c change is slightly unrelated, but needed for the gigi patch.
> It makes it possible to use the CALL_EXPR_RETURN_SLOT_OPTimization for calls
> to functions returning a type with non-fixed size, if the front-end thinks it
> is safe to do so.
>
> All this stuff should only affect the Ada compiler.  OK for mainline?

How did you test the patch?  I believe that removing

-  if (TREE_CODE (exp) == CALL_EXPR && fndecl && DECL_RESULT (fndecl)
-      && DECL_BY_REFERENCE (DECL_RESULT (fndecl)))

might regress the C++ frontend as that also sets DECL_BY_REFERENCE
on RESULT_DECLs.

If not then the fndecl variable is completely unused after your patch?

The patch is ok if C++ folks are fine with it and with the fndecl
variable removed.

Thanks,
Richard.

>
> 2010-04-07  Eric Botcazou  <ebotcazou@adacore.com>
>
>        * tree.h (TREE_ADDRESSABLE): Document its effect for function types.
>        * calls.c (expand_call): Pass the function type to aggregate_value_p.
>        * function.c (aggregate_value_p): Do not honor DECL_BY_REFERENCE on
>        the target function of a CALL_EXPR.  Honor TREE_ADDRESSABLE on the
>        function type instead.
>
>        * gimplify.c (gimplify_modify_expr_rhs) <WITH_SIZE_EXPR>: New case.
>
>
> --
> Eric Botcazou
>



More information about the Gcc-patches mailing list