diff mbox

[C++] Fix infinite recursion trying to gimplify a read from empty class via pointer to volatile (PR c++/46160)

Message ID 20101105175124.GL29412@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Nov. 5, 2010, 5:51 p.m. UTC
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.


	Jakub

Comments

Jason Merrill Nov. 5, 2010, 6:12 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

--- 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);
+}