@@ -590,6 +590,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) == INDIRECT_REF
+ && TREE_THIS_VOLATILE (op1))
+ {
+ /* Similarly for volatile INDIRECT_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);
@@ -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);
+}