re PR c/89872 (GCC does not generate read access to volatile compound literal)
authorJakub Jelinek <jakub@redhat.com>
Fri, 29 Mar 2019 19:32:20 +0000 (20:32 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 29 Mar 2019 19:32:20 +0000 (20:32 +0100)
PR c/89872
* gimplify.c (gimplify_compound_literal_expr): Don't optimize a
non-addressable complit into its initializer if it is volatile.

* gcc.dg/tree-ssa/pr89872.c: New test.

From-SVN: r270023

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr89872.c [new file with mode: 0644]

index 15b2408..5639435 100644 (file)
@@ -1,3 +1,9 @@
+2019-03-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/89872
+       * gimplify.c (gimplify_compound_literal_expr): Don't optimize a
+       non-addressable complit into its initializer if it is volatile.
+
 2019-03-29  Roman Zhuykov  <zhroma@ispras.ru>
 
        * opts-common.c (integral_argument): Set errno properly in one case.
index e264700..6ac1b71 100644 (file)
@@ -4665,6 +4665,7 @@ gimplify_compound_literal_expr (tree *expr_p, gimple_seq *pre_p,
      otherwise we'd generate a new temporary, and we can as well just
      use the decl we already have.  */
   else if (!TREE_ADDRESSABLE (decl)
+          && !TREE_THIS_VOLATILE (decl)
           && init
           && (fallback & fb_lvalue) == 0
           && gimple_test_f (init))
index 9d6743d..1398b23 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/89872
+       * gcc.dg/tree-ssa/pr89872.c: New test.
+
 2019-03-29  Roman Zhuykov  <zhroma@ispras.ru>
 
        * gcc.dg/diag-sanity.c: New test.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr89872.c b/gcc/testsuite/gcc.dg/tree-ssa/pr89872.c
new file mode 100644 (file)
index 0000000..c081cd5
--- /dev/null
@@ -0,0 +1,27 @@
+/* PR c/89872 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times " ={v} 1;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " ={v} 2;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " ={v} 3;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " ={v} 4;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " ={v} 0;" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times " ={v} " 10 "optimized" } } */
+
+void
+foo (void)
+{
+  (volatile int){1} + (volatile int){2};
+}
+
+void
+bar (void)
+{
+  (volatile int){3};
+}
+
+void
+baz (void)
+{
+  (volatile int){4} / (volatile int){0};
+}