[C++ RFH] PR 56961

Paolo Carlini paolo.carlini@oracle.com
Thu Jun 5 14:32:00 GMT 2014


Hi,

On 06/05/2014 03:35 PM, Richard Biener wrote:
> On Thu, Jun 5, 2014 at 3:26 PM, Paolo Carlini <paolo.carlini@oracle.com> wrote:
>> Hi,
>>
>>
>> On 06/05/2014 03:20 PM, Richard Biener wrote:
>>> I think the operands have to be reversed though - the type matches that of
>>> op0. Sorry ;)
>> Something like this, then?
> Yes.  I suppose it's ok to re-order side-effects lhs, rhs to rhs, lhs?
> Otherwise you'd need to do sth like
>
>    op0 = save_expr (op0);
>    *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
>                              op0,
>                              build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
>                                         build_fold_addr_expr (op1), op0));
>
> (which may or may not work or be a good idea with zero-size aggregate op0)
In any case, I think that we would not regress on this... and, well, we 
have plenty of time for further tweaks (this goes to mainline only, of 
course). The below passes testing, if nobody has further comments 
tomorrow I will commit it.

Thanks again,
Paolo.

//////////////////////////
-------------- next part --------------
/cp
2014-06-05  Richard Biener  <rguenther@suse.de>
	    Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/56961
	* cp-gimplify.c (cp_gimplify_expr, [MODIFY_EXPR]): Rework
	handling of empty classes.

/testsuite
2014-06-05  Richard Biener  <rguenther@suse.de>
	    Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/56961
	* g++.dg/parse/pr56961.C: New.
-------------- next part --------------
Index: cp/cp-gimplify.c
===================================================================
--- cp/cp-gimplify.c	(revision 211274)
+++ cp/cp-gimplify.c	(working copy)
@@ -629,19 +629,12 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p,
 
 	       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))
-	      {
-		/* 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 if (TREE_THIS_VOLATILE (op1)
+		     && (REFERENCE_CLASS_P (op1) || DECL_P (op1)))
+	      *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
+				build_fold_addr_expr (op1), op0);
 	    else
 	      *expr_p = build2 (COMPOUND_EXPR, TREE_TYPE (*expr_p),
 				op0, op1);
Index: testsuite/g++.dg/parse/pr56961.C
===================================================================
--- testsuite/g++.dg/parse/pr56961.C	(revision 0)
+++ testsuite/g++.dg/parse/pr56961.C	(working copy)
@@ -0,0 +1,16 @@
+// PR c++/56961
+
+struct foo { };
+
+typedef struct
+{
+  volatile foo fields;
+} CSPHandleState;
+ 
+CSPHandleState a;
+
+void fn1 ()
+{
+  CSPHandleState b;
+  b.fields = foo();  // { dg-error "discards qualifiers" }
+}


More information about the Gcc-patches mailing list