From: Jakub Jelinek Date: Thu, 2 Jun 2016 16:36:04 +0000 (+0200) Subject: re PR c++/71372 (C++ FE drops TREE_THIS_VOLATILE in cp_fold on all tcc_reference... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0633ee10ed6a1b53f5adde1f5832634cd51d26f7;p=gcc.git re PR c++/71372 (C++ FE drops TREE_THIS_VOLATILE in cp_fold on all tcc_reference trees) 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2850334efff..651407151ab 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2016-06-02 Jakub Jelinek + + 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 * pt.c (instantiate_decl): Avoid recalculation. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 0ba5aa956ee..4fc8ba1afca 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 270bde1e315..899e2bced1f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2016-06-02 Jakub Jelinek + 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 index 00000000000..943adab628d --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr71372.c @@ -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" } } */