Hi!

We shouldn't optimize volatile compound literals to their initializers, even
when they are not addressable.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk.

2019-03-29  Jakub Jelinek  <ja...@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.

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

--- gcc/gimplify.c.jj   2019-03-19 09:10:54.906666420 +0100
+++ gcc/gimplify.c      2019-03-29 09:53:09.337256784 +0100
@@ -4665,6 +4665,7 @@ gimplify_compound_literal_expr (tree *ex
      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))
--- gcc/testsuite/gcc.dg/tree-ssa/pr89872.c.jj  2019-03-29 10:09:55.789803295 
+0100
+++ gcc/testsuite/gcc.dg/tree-ssa/pr89872.c     2019-03-29 10:11:44.841018571 
+0100
@@ -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};
+}

        Jakub

Reply via email to