[PATCH][PR65818][bootstrap,hppa] Return side-effect free result in gimplify_va_arg_internal

Tom de Vries Tom_deVries@mentor.com
Sat Apr 25 12:35:00 GMT 2015


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?

Thanks,
- Tom

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Return-side-effect-free-result-in-gimplify_va_arg_in.patch
Type: text/x-patch
Size: 1061 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20150425/df42dca3/attachment.bin>


More information about the Gcc-patches mailing list