From: Tom de Vries <Tom_deVries@mentor.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Cc: John David Anglin <dave.anglin@bell.net>
Subject: [PATCH][PR65818][bootstrap,hppa] Return side-effect free result in gimplify_va_arg_internal
Date: Sat, 25 Apr 2015 12:35:00 -0000 [thread overview]
Message-ID: <553B89FB.7000009@mentor.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1940 bytes --]
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
[-- Attachment #2: 0001-Return-side-effect-free-result-in-gimplify_va_arg_in.patch --]
[-- Type: text/x-patch, Size: 1061 bytes --]
Return side-effect free result in gimplify_va_arg_internal
2015-04-22 Tom de Vries <tom@codesourcery.com>
PR tree-optimization/65818
* gimplify.c (gimplify_va_arg_internal): Ensure that only side-effect
free values are returned.
---
gcc/gimplify.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index c68bd47..fe54e53 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -9352,7 +9352,12 @@ gimplify_va_arg_internal (tree valist, tree type, location_t loc,
else
gimplify_expr (&valist, pre_p, post_p, is_gimple_min_lval, fb_lvalue);
- return targetm.gimplify_va_arg_expr (valist, type, pre_p, post_p);
+ tree expr = targetm.gimplify_va_arg_expr (valist, type, pre_p, post_p);
+ gcc_assert (TREE_CODE (expr) == MEM_REF);
+ if (!is_gimple_mem_ref_addr (TREE_OPERAND (expr, 0)))
+ gimplify_expr (&TREE_OPERAND (expr, 0), pre_p, post_p,
+ is_gimple_mem_ref_addr, fb_rvalue);
+ return expr;
}
/* Gimplify __builtin_va_arg, aka VA_ARG_EXPR, which is not really a
--
1.9.1
next reply other threads:[~2015-04-25 12:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-25 12:35 Tom de Vries [this message]
2015-04-27 8:17 ` Richard Biener
2015-04-27 13:06 ` Tom de Vries
2015-04-27 13:40 ` Richard Biener
2015-04-27 15:04 ` Tom de Vries
2015-04-28 10:49 ` Richard Biener
2015-04-28 21:59 ` Tom de Vries
2015-04-29 9:53 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=553B89FB.7000009@mentor.com \
--to=tom_devries@mentor.com \
--cc=dave.anglin@bell.net \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).