]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/82340 (volatile ignored in compound literal)
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Jun 2018 16:43:59 +0000 (18:43 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Jun 2018 16:43:59 +0000 (18:43 +0200)
Backported from mainline
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.

* gcc.dg/tree-ssa/pr82340.c: New test.

From-SVN: r262027

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 1a9c04045a6fa19f6fe20cc7e70a7e4aa45f7a09..5c7fe67aa5834873eb786084be236a088a44ed14 100644 (file)
@@ -1,3 +1,12 @@
+2018-06-25  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       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-12-10  Tom de Vries  <tom@codesourcery.com>
 
        backport from trunk:
index e8bafedd73573053be9544002b01c11940b22a38..ef2780c38746b7a49f2785576d83f2e8aed9480e 100644 (file)
@@ -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))
index 2404a59569a6d72eef66414810965b913d8d51ff..b382215ba5509c26ffce336e4cf91c18ddb207ec 100644 (file)
@@ -1,6 +1,11 @@
 2018-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2017-09-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/82340
+       * gcc.dg/tree-ssa/pr82340.c: New test.
+
        2017-09-27  Jakub Jelinek  <jakub@redhat.com>
 
        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 (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;
+}