From patchwork Mon Apr 11 19:52:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 90641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 96378B6F15 for ; Tue, 12 Apr 2011 05:52:55 +1000 (EST) Received: (qmail 7272 invoked by alias); 11 Apr 2011 19:52:54 -0000 Received: (qmail 7264 invoked by uid 22791); 11 Apr 2011 19:52:53 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 11 Apr 2011 19:52:48 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3BJqdXi009317 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 11 Apr 2011 15:52:40 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p3BJqd9L011763 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 11 Apr 2011 15:52:39 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p3BJqcrq008170; Mon, 11 Apr 2011 21:52:38 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p3BJqcRX008168; Mon, 11 Apr 2011 21:52:38 +0200 Date: Mon, 11 Apr 2011 21:52:38 +0200 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix ICE with C compound literals (PR c/48517) Message-ID: <20110411195238.GA17079@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 PR c/48517 * c-typeck.c (store_init_value): Set TREE_TYPE (decl) to qualified type. * gcc.dg/pr48517.c: New test. Jakub --- 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); +}