+2016-06-02 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/71372
+ * cp-gimplify.c (cp_fold): For INDIRECT_REF, if the folded expression
+ is INDIRECT_REF or MEM_REF, copy over TREE_READONLY, TREE_SIDE_EFFECTS
+ and TREE_THIS_VOLATILE flags. For ARRAY_REF and ARRAY_RANGE_REF, copy
+ over TREE_READONLY, TREE_SIDE_EFFECTS and TREE_THIS_VOLATILE flags
+ to the newly built tree.
+
2016-05-31 Jason Merrill <jason@redhat.com>
* pt.c (instantiate_decl): Avoid recalculation.
if (op0 == error_mark_node)
x = error_mark_node;
else
- x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
+ {
+ x = fold_build1_loc (loc, code, TREE_TYPE (x), op0);
+ if (code == INDIRECT_REF
+ && (INDIRECT_REF_P (x) || TREE_CODE (x) == MEM_REF))
+ {
+ TREE_READONLY (x) = TREE_READONLY (org_x);
+ TREE_SIDE_EFFECTS (x) = TREE_SIDE_EFFECTS (org_x);
+ TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
+ }
+ }
}
else
x = fold (x);
|| op3 == error_mark_node)
x = error_mark_node;
else
- x = build4_loc (loc, code, TREE_TYPE (x), op0, op1, op2, op3);
+ {
+ x = build4_loc (loc, code, TREE_TYPE (x), op0, op1, op2, op3);
+ TREE_READONLY (x) = TREE_READONLY (org_x);
+ TREE_SIDE_EFFECTS (x) = TREE_SIDE_EFFECTS (org_x);
+ TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (org_x);
+ }
}
x = fold (x);
2016-06-02 Jakub Jelinek <jakub@redhat.com>
+ PR c++/71372
+ * c-c++-common/pr71372.c: New test.
+
* gcc.dg/cpp/source_date_epoch-1.c (main): Test __DATE__ and
__TIME__ strings with __builtin_strcmp instead of printf and
dg-output.
--- /dev/null
+/* PR c++/71372 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+void
+foo (volatile int *p, int q)
+{
+ *(volatile int *)p = 0;
+ *(p + (q - q) + 1) = 0;
+ *(p + (q - q) + 2) = 0;
+ *(p + (q - q) + 3) = 0;
+}
+
+/* { dg-final { scan-tree-dump-times " ={v} " 4 "optimized" } } */