On Sat, Apr 25, 2015 at 2:35 PM, Tom de Vries <tom_devr...@mentor.com> wrote:
> Hi,
>
> this patch fixes PR65818, and hppa bootstrap.
>
> When compiling gcc/libiberty/vprintf-support.c, the following va_arg is
> compiled:
> ...
>  (void) __builtin_va_arg(ap, double);
> ...
>
> This results in the following ifn_va_arg at gimple level, with a NULL_TREE
> lhs:
> ...
>   VA_ARG (&ap, 0B);
> ...
>
> We start expanding the ifn_va_arg in expand_ifn_va_arg_1 by calling
> gimplify_va_arg_internal:
> ...
>         expr = gimplify_va_arg_internal (ap, type, gimple_location (stmt),
>                                          &pre, &post);
> ...
>
> Subsequently, because the lhs is NULL_TREE, we skip generating the assign to
> the lhs:
> ...
>         lhs = gimple_call_lhs (stmt);
>         if (lhs != NULL_TREE)
>           {
>             gcc_assert (useless_type_conversion_p (TREE_TYPE (lhs), type));
>
>             if (gimple_call_num_args (stmt) == 3)
>               {
>                 /* We've transported the size of with WITH_SIZE_EXPR here as
>                    the 3rd argument of the internal fn call.  Now reinstate
>                    it.  */
>                 tree size = gimple_call_arg (stmt, 2);
>                 expr = build2 (WITH_SIZE_EXPR, TREE_TYPE (expr), expr,
> size);
>               }
>
>             /* We use gimplify_assign here, rather than gimple_build_assign,
>                because gimple_assign knows how to deal with variable-sized
>                types.  */
>             gimplify_assign (lhs, expr, &pre);
>           }
> ...
>
> We assume here that any side-effects related to updating ap have been
> generated into pre/post by gimplify_va_arg_internal, and that it's safe to
> ignore expr.
>
> Turns out, that's not the case for hppa. The target hook
> hppa_gimplify_va_arg_expr (called from gimplify_va_arg_internal) returns an
> expression that still contains a side-effect:
> ...
> *(double *) (ap = ap + 4294967288 & 4294967288B)
> ...
>
> This patch fixes that by gimplifying the address expression of the mem-ref
> returned by the target hook (borrowing code from gimplify_expr, case
> MEM_REF).
>
> Bootstrapped and reg-tested on x86_64.
>
> Bootstrapped and reg-tested on hppa2.0w-hp-hpux11.11.
>
> OK for trunk?

Hmm, that assert looks suspicious...

Can't you simply always do

  gimplify_expr (expr, pre_p, post_p, is_gimple_lvalue, fb_lvalue);

?

Richard.

> Thanks,
> - Tom
>

Reply via email to