This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C PATCH] Fix flags on compound literal VAR_DECLs (PR c/82340)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "Joseph S. Myers" <joseph at codesourcery dot com>, Marek Polacek <polacek at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 28 Sep 2017 20:33:36 +0200
- Subject: [C PATCH] Fix flags on compound literal VAR_DECLs (PR c/82340)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CB3AD26822
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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 <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.
--- 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