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
This commit is contained in:
Jakub Jelinek 2019-03-29 20:32:20 +01:00 committed by Jakub Jelinek
parent 7ad99f7d21
commit 77527d8ac4
4 changed files with 39 additions and 0 deletions

View 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.

View 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))

View 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.

View File

@ -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};
}