public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/56961] stack overflow in gimplifier with volatile field
Date: Thu, 05 Jun 2014 12:39:00 -0000 [thread overview]
Message-ID: <bug-56961-4-7iCtVaRuLp@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-56961-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56961
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #8)
> (In reply to Richard Biener from comment #7)
> > I suggest
> >
> > Index: gcc/cp/cp-gimplify.c
> > ===================================================================
> > --- gcc/cp/cp-gimplify.c (revision 211262)
> > +++ gcc/cp/cp-gimplify.c (working copy)
> > @@ -630,18 +630,8 @@ cp_gimplify_expr (tree *expr_p, gimple_s
> > Also drop volatile variables on the RHS to avoid infinite
> > recursion from gimplify_expr trying to load the value. */
> > if (!TREE_SIDE_EFFECTS (op1)
> > - || (DECL_P (op1) && TREE_THIS_VOLATILE (op1)))
> > + || TREE_THIS_VOLATILE (op1))
> > *expr_p = op0;
> > - else if (TREE_CODE (op1) == MEM_REF
> > - && TREE_THIS_VOLATILE (op1))
> > - {
> > - /* Similarly for volatile MEM_REFs on the RHS. */
> > - if (!TREE_SIDE_EFFECTS (TREE_OPERAND (op1, 0)))
> > - *expr_p = op0;
> > - else
> > - *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
> > - TREE_OPERAND (op1, 0), op0);
> > - }
> > else
> > *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
> > op0, op1);
>
> This might of course drop arbitrary side-effects of op1 such as
> a volatile load from a.b[foo()] where foo () would be dropped.
>
> So it isn't really correct.
The following should preserve those.
Index: gcc/cp/cp-gimplify.c
===================================================================
--- gcc/cp/cp-gimplify.c (revision 211262)
+++ gcc/cp/cp-gimplify.c (working copy)
@@ -629,18 +629,14 @@ cp_gimplify_expr (tree *expr_p, gimple_s
Also drop volatile variables on the RHS to avoid infinite
recursion from gimplify_expr trying to load the value. */
- if (!TREE_SIDE_EFFECTS (op1)
- || (DECL_P (op1) && TREE_THIS_VOLATILE (op1)))
+ if (!TREE_SIDE_EFFECTS (op1))
*expr_p = op0;
- else if (TREE_CODE (op1) == MEM_REF
- && TREE_THIS_VOLATILE (op1))
+ else if (TREE_THIS_VOLATILE (op1)
+ && (REFERENCE_CLASS_P (op1) || DECL_P (op1)))
{
- /* Similarly for volatile MEM_REFs on the RHS. */
- if (!TREE_SIDE_EFFECTS (TREE_OPERAND (op1, 0)))
- *expr_p = op0;
- else
- *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
- TREE_OPERAND (op1, 0), op0);
+ *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
+ op0, build_fold_addr_expr (op1));
+
}
else
*expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
next prev parent reply other threads:[~2014-06-05 12:39 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-15 7:39 [Bug c++/56961] New: cycle between do_spec_1() / process_brace_body() / handle_braces() dimhen at gmail dot com
2013-04-15 7:45 ` [Bug c++/56961] Segfault with volatile field pinskia at gcc dot gnu.org
2013-04-15 7:50 ` [Bug c++/56961] stack overflow in gimplifier " pinskia at gcc dot gnu.org
2013-04-15 8:01 ` dimhen at gmail dot com
2014-01-06 19:33 ` dimhen at gmail dot com
2014-06-05 12:16 ` paolo.carlini at oracle dot com
2014-06-05 12:29 ` rguenth at gcc dot gnu.org
2014-06-05 12:33 ` rguenth at gcc dot gnu.org
2014-06-05 12:35 ` rguenth at gcc dot gnu.org
2014-06-05 12:39 ` rguenth at gcc dot gnu.org [this message]
2014-06-05 14:16 ` paolo.carlini at oracle dot com
2014-06-05 17:35 ` paolo at gcc dot gnu.org
2014-06-05 17:36 ` paolo.carlini at oracle dot com
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=bug-56961-4-7iCtVaRuLp@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@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).