public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Fix infinite recursion trying to gimplify a read from empty class via pointer to volatile (PR c++/46160)
@ 2010-11-05 18:03 Jakub Jelinek
  2010-11-05 18:19 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2010-11-05 18:03 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

cp_gimplify_expr already has code to avoid infinite recursion if
op1 is a volatile decl, but if it is volatile MEM_REF, we get the
same infinite recursion.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2010-11-05  Jakub Jelinek  <jakub@redhat.com>

	PR c++/46160
	* cp-gimplify.c (cp_gimplify_expr): Drop volatile MEM_REFs
	on the RHS to avoid infinite recursion with gimplify_expr.

	* g++.dg/opt/empty2.C: New test.

--- gcc/cp/cp-gimplify.c.jj	2010-11-01 09:07:00.000000000 +0100
+++ gcc/cp/cp-gimplify.c	2010-11-05 15:56:15.000000000 +0100
@@ -595,6 +595,16 @@ cp_gimplify_expr (tree *expr_p, gimple_s
 	    if (!TREE_SIDE_EFFECTS (op1)
 		|| (DECL_P (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);
--- gcc/testsuite/g++.dg/opt/empty2.C.jj	2010-11-05 16:04:12.000000000 +0100
+++ gcc/testsuite/g++.dg/opt/empty2.C	2010-11-05 16:08:49.000000000 +0100
@@ -0,0 +1,18 @@
+// PR c++/46160
+// { dg-do compile }
+
+struct S
+{
+  enum E { A };
+} s;
+volatile S t;
+
+void f (S::E);
+
+void
+g ()
+{
+  volatile S *p = &s;
+  f (p->A);
+  f (t.A);
+}

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ PATCH] Fix infinite recursion trying to gimplify a read from empty class via pointer to volatile (PR c++/46160)
  2010-11-05 18:03 [C++ PATCH] Fix infinite recursion trying to gimplify a read from empty class via pointer to volatile (PR c++/46160) Jakub Jelinek
@ 2010-11-05 18:19 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2010-11-05 18:19 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

OK.

Jason

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-11-05 18:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-05 18:03 [C++ PATCH] Fix infinite recursion trying to gimplify a read from empty class via pointer to volatile (PR c++/46160) Jakub Jelinek
2010-11-05 18:19 ` Jason Merrill

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).