Hi! As the testcase shows, while build_compound_literal had some code to set up TREE_READONLY flag on compound literal VAR_DECLs, it didn't handle volatile nor restrict quals.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-09-28 Jakub Jelinek <ja...@redhat.com> 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. --- gcc/c/c-decl.c.jj 2017-09-19 16:38:14.000000000 +0200 +++ gcc/c/c-decl.c 2017-09-27 15:18:53.066566172 +0200 @@ -5247,9 +5247,7 @@ build_compound_literal (location_t loc, 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)) --- gcc/testsuite/gcc.dg/tree-ssa/pr82340.c.jj 2017-09-27 16:01:36.696296732 +0200 +++ gcc/testsuite/gcc.dg/tree-ssa/pr82340.c 2017-09-27 16:02:09.262886860 +0200 @@ -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; +} Jakub