From: Jakub Jelinek Date: Mon, 25 Jun 2018 16:43:59 +0000 (+0200) Subject: backport: re PR c/82340 (volatile ignored in compound literal) X-Git-Tag: releases/gcc-6.5.0~255 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95e03a045bc9aa71b6ff5616fab4d6563c5a624f;p=thirdparty%2Fgcc.git backport: re PR c/82340 (volatile ignored in compound literal) Backported from mainline 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. * gcc.dg/tree-ssa/pr82340.c: New test. From-SVN: r262027 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 1a9c04045a6f..5c7fe67aa583 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,12 @@ +2018-06-25 Jakub Jelinek + + Backported from mainline + 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-12-10 Tom de Vries backport from trunk: diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index e8bafedd7357..ef2780c38746 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5092,9 +5092,7 @@ build_compound_literal (location_t loc, tree type, tree init, bool non_const) TREE_USED (decl) = 1; DECL_READ_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 2404a59569a6..b382215ba550 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2017-09-29 Jakub Jelinek + + PR c/82340 + * gcc.dg/tree-ssa/pr82340.c: New test. + 2017-09-27 Jakub Jelinek PR c++/82159 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 000000000000..ad9f1cfcee16 --- /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; +}