From 2a38995899548c685e8bd794f79c5aad80fc6ef0 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 29 Sep 2017 09:35:37 +0200 Subject: [PATCH] re PR c/82340 (volatile ignored in compound literal) PR c/82340 * c-decl.c (build_compound_literal): Use c_apply_type_quals_to_decl instead of trying to set just TREE_READONLY manually. * gcc.dg/tree-ssa/pr82340.c: New test. From-SVN: r253280 --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-decl.c | 4 +--- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/tree-ssa/pr82340.c | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr82340.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 135445e1bbd..496b767cb51 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2017-09-29 Jakub Jelinek + + PR c/82340 + * c-decl.c (build_compound_literal): Use c_apply_type_quals_to_decl + instead of trying to set just TREE_READONLY manually. + 2017-09-16 Tom de Vries PR c/81875 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 71214982329..080a2e9c0bd 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5247,9 +5247,7 @@ build_compound_literal (location_t loc, tree type, tree init, bool non_const) DECL_ARTIFICIAL (decl) = 1; DECL_IGNORED_P (decl) = 1; TREE_TYPE (decl) = type; - TREE_READONLY (decl) = (TYPE_READONLY (type) - || (TREE_CODE (type) == ARRAY_TYPE - && TYPE_READONLY (TREE_TYPE (type)))); + c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl); store_init_value (loc, decl, init, NULL_TREE); if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4f3e428d0e1..e0eade336b3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-09-29 Jakub Jelinek + PR c/82340 + * gcc.dg/tree-ssa/pr82340.c: New test. + * g++.dg/eh/uncaught3.C: Add -Wno-deprecated for c++17. 2017-09-28 Paolo Carlini diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr82340.c b/gcc/testsuite/gcc.dg/tree-ssa/pr82340.c new file mode 100644 index 00000000000..ad9f1cfcee1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr82340.c @@ -0,0 +1,14 @@ +/* PR c/82340 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ssa" } */ +/* { dg-final { scan-tree-dump "D.\[0-9]*\\\[0\\\] ={v} 77;" "ssa" } } */ + +int +foo (void) +{ + int i; + volatile char *p = (volatile char[1]) { 77 }; + for (i = 1; i < 10; i++) + *p = 4; + return *p; +} -- 2.30.2