public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: "Joseph S. Myers" <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix ICE with C compound literals (PR c/48517)
Date: Mon, 11 Apr 2011 19:52:00 -0000	[thread overview]
Message-ID: <20110411195238.GA17079@tyan-ft48-01.lab.bos.redhat.com> (raw)

Hi!

On the following testcase build_unary_op ICEs, because
the element type of the array variable (which is TREE_READONLY)
unexpectedly is not TYPE_READONLY.
The problem seems to come from store_init_value, which replaces
the type of the variable with build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
on which it sets TYPE_DOMAIN.  The following patch restores the
quals back.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.6?

2011-04-11  Jakub Jelinek  <jakub@redhat.com>

	PR c/48517
	* c-typeck.c (store_init_value): Set TREE_TYPE (decl) to
	qualified type.

	* gcc.dg/pr48517.c: New test.

--- gcc/c-typeck.c.jj	2011-03-31 08:51:03.000000000 +0200
+++ gcc/c-typeck.c	2011-04-11 15:19:25.000000000 +0200
@@ -5773,11 +5773,13 @@ store_init_value (location_t init_loc, t
 	      /* For int foo[] = (int [3]){1}; we need to set array size
 		 now since later on array initializer will be just the
 		 brace enclosed list of the compound literal.  */
+	      tree etype = strip_array_types (TREE_TYPE (decl));
 	      type = build_distinct_type_copy (TYPE_MAIN_VARIANT (type));
-	      TREE_TYPE (decl) = type;
 	      TYPE_DOMAIN (type) = TYPE_DOMAIN (TREE_TYPE (cldecl));
 	      layout_type (type);
 	      layout_decl (cldecl, 0);
+	      TREE_TYPE (decl)
+		= c_build_qualified_type (type, TYPE_QUALS (etype));
 	    }
 	}
     }
--- gcc/testsuite/gcc.dg/pr48517.c.jj	2011-04-11 15:21:59.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr48517.c	2011-04-11 15:21:16.000000000 +0200
@@ -0,0 +1,13 @@
+/* PR c/48517 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+void bar (const unsigned short *);
+
+void
+foo (void)
+{
+  static const unsigned short array[] = (const unsigned short []) { 0x0D2B };
+  const unsigned short *ptr = array;
+  bar (ptr);
+}

	Jakub

             reply	other threads:[~2011-04-11 19:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-11 19:52 Jakub Jelinek [this message]
2011-04-11 21:29 ` Joseph S. Myers
2011-04-12 15:48 ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110411195238.GA17079@tyan-ft48-01.lab.bos.redhat.com \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).