From 77527d8ac499e55ff609ce112e0c68ebd8836704 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 29 Mar 2019 20:32:20 +0100 Subject: [PATCH] re PR c/89872 (GCC does not generate read access to volatile compound literal) 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 | 6 ++++++ gcc/gimplify.c | 1 + gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/pr89872.c | 27 +++++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr89872.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 15b24087e28..563943567ca 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-03-29 Jakub Jelinek + + 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 * opts-common.c (integral_argument): Set errno properly in one case. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index e264700989f..6ac1b718ebd 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -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)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9d6743d725a..1398b23424c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-03-29 Jakub Jelinek + + PR c/89872 + * gcc.dg/tree-ssa/pr89872.c: New test. + 2019-03-29 Roman Zhuykov * 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 index 00000000000..c081cd5f9ec --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr89872.c @@ -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}; +} -- 2.30.2