From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20710 invoked by alias); 5 Jun 2014 12:39:56 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 20672 invoked by uid 48); 5 Jun 2014 12:39:53 -0000 From: "rguenth at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: ice-on-invalid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-06/txt/msg00367.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56961 --- Comment #9 from Richard Biener --- (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),