re PR c++/71372 (C++ FE drops TREE_THIS_VOLATILE in cp_fold on all tcc_reference...
authorJakub Jelinek <jakub@redhat.com>
Thu, 2 Jun 2016 16:36:04 +0000 (18:36 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 2 Jun 2016 16:36:04 +0000 (18:36 +0200)
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.

* c-c++-common/pr71372.c: New test.

From-SVN: r237041

gcc/cp/ChangeLog
gcc/cp/cp-gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr71372.c [new file with mode: 0644]

index 2850334efff75b26be9b77c57069a17142715246..651407151abbc185a7e1a91fa27a591d1bbce824 100644 (file)
@@ -1,3 +1,12 @@
+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.
index 0ba5aa956ee1f95f8bc38211449a4cf0d9e555f9..4fc8ba1afcacc379e89a2e6dbf5c477fa391b4b3 100644 (file)
@@ -2035,7 +2035,16 @@ cp_fold (tree x)
          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);
@@ -2312,7 +2321,12 @@ cp_fold (tree 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);
index 270bde1e3155d446b4f20da7b07342cc57d83d26..899e2bced1fc3a9b62ab6248b456d029ae502653 100644 (file)
@@ -1,5 +1,8 @@
 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.
diff --git a/gcc/testsuite/c-c++-common/pr71372.c b/gcc/testsuite/c-c++-common/pr71372.c
new file mode 100644 (file)
index 0000000..943adab
--- /dev/null
@@ -0,0 +1,14 @@
+/* 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" } } */