re PR c/82340 (volatile ignored in compound literal)
authorJakub Jelinek <jakub@redhat.com>
Fri, 29 Sep 2017 07:35:37 +0000 (09:35 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 29 Sep 2017 07:35:37 +0000 (09:35 +0200)
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
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr82340.c [new file with mode: 0644]

index 135445e1bbd178669141744e313b2c730d360724..496b767cb51471bd022a97a0bdb7120acad9f4c2 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-29  Jakub Jelinek  <jakub@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.
+
 2017-09-16  Tom de Vries  <tom@codesourcery.com>
 
        PR c/81875
index 712149823290a32bab163fb5de8642b053371f16..080a2e9c0bd7a8918a9421a3f194326e65738814 100644 (file)
@@ -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))
index 4f3e428d0e1ca25194f7e4904b8260015fbc10bb..e0eade336b3a4d0f5ca70d0e7b7f0f208023b974 100644 (file)
@@ -1,5 +1,8 @@
 2017-09-29  Jakub Jelinek  <jakub@redhat.com>
 
+       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  <paolo.carlini@oracle.com>
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr82340.c b/gcc/testsuite/gcc.dg/tree-ssa/pr82340.c
new file mode 100644 (file)
index 0000000..ad9f1cf
--- /dev/null
@@ -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;
+}