This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/71372] [6/7 Regression] C++ FE drops TREE_THIS_VOLATILE in cp_fold on all tcc_reference trees


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71372

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
On the C++ cp_fold side, I think
--- cp-gimplify.c.jj1   2016-05-26 10:38:01.000000000 +0200
+++ cp-gimplify.c       2016-06-02 10:21:33.903655321 +0200
@@ -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);

could be enough, at least I don't see folding of any other *_REF right now.
In the C FE, I wonder if fold or fold_build1_loc can turn INDIRECT_REF into
MEM_REF, if yes, then it would be wrong.  Also for COMPONENT_REF the C FE
doesn't copy TREE_SIDE_EFFECTS bit, that might be incorrect if it copies
TREE_THIS_VOLATILE?
And, for C++ I'm missing e.g. any kind of folding of COMPONENT_REF, that is
really strange.  In fold_builtin_arith_overflow, I guess we also fail to add
TREE_THIS_VOLATILE/TREE_SIDE_EFFECTS if the pointer points to volatile type.
Plus fold...

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]