public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C PATCH] Fix flags on compound literal VAR_DECLs (PR c/82340)
@ 2017-09-28 18:33 Jakub Jelinek
  2017-09-28 19:35 ` Joseph Myers
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-09-28 18:33 UTC (permalink / raw)
  To: Joseph S. Myers, Marek Polacek; +Cc: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C PATCH] Fix flags on compound literal VAR_DECLs (PR c/82340)
  2017-09-28 18:33 [C PATCH] Fix flags on compound literal VAR_DECLs (PR c/82340) Jakub Jelinek
@ 2017-09-28 19:35 ` Joseph Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph Myers @ 2017-09-28 19:35 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Marek Polacek, gcc-patches

On Thu, 28 Sep 2017, Jakub Jelinek wrote:

> 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?

OK.

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-28 19:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-28 18:33 [C PATCH] Fix flags on compound literal VAR_DECLs (PR c/82340) Jakub Jelinek
2017-09-28 19:35 ` Joseph Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).