From patchwork Fri Sep 14 21:17:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 184044 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 7348E2C00AD for ; Sat, 15 Sep 2012 07:18:03 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1348262284; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=Rq0U5PR i1rfBhiwlCsse2cfp62I=; b=uML/J0/Np4mZ+u5LDOdi1KWLTHO/Tlq0EH84cJg 9O/zPNrFuSq7ZI+1T3Icsw3RZY641NGask4bLEH4c1gCATwV7cbOEmD2QS9jDzuU Ie7F5jDH9fNcAOVAZ5We3f+CBjazeCsO5xoR6UAPAk/QrXiKeT07xtKe94dog+xU rk4s= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Subject:Message-ID:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=Ec4FNw8tPY0cRlDUHdYYw3yIEdhG4lxDwnGNk+pIKPIEJ1R6flrMylGiX2sgO+ B8WyZvSoAKAkW3UBm0LqAf+uVlJLAOfoGHv4PTe+OD1ia46mMUzkqrjbouKcJhUs XLigtfRJJpmubmhg2XAZ5tfxW++b7ayBEXenn5QAo3kV4=; Received: (qmail 9359 invoked by alias); 14 Sep 2012 21:18:00 -0000 Received: (qmail 9350 invoked by uid 22791); 14 Sep 2012 21:17:58 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 14 Sep 2012 21:17:45 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1TCdGi-0007nS-Kb from joseph_myers@mentor.com for gcc-patches@gcc.gnu.org; Fri, 14 Sep 2012 14:17:44 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 14 Sep 2012 14:17:44 -0700 Received: from digraph.polyomino.org.uk (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Fri, 14 Sep 2012 22:17:42 +0100 Received: from jsm28 (helo=localhost) by digraph.polyomino.org.uk with local-esmtp (Exim 4.76) (envelope-from ) id 1TCdGf-0004ID-SO for gcc-patches@gcc.gnu.org; Fri, 14 Sep 2012 21:17:41 +0000 Date: Fri, 14 Sep 2012 21:17:41 +0000 From: "Joseph S. Myers" To: Subject: Fix C ICE with casts to pointers to VLAs (PR c/54552) Message-ID: MIME-Version: 1.0 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 Bug 54552 is a C front-end regression involving ICEs when an expression involving C_MAYBE_CONST_EXPR, such as a compound literal of variably modified type, is cast to a variably modified type. This patch fixes it by doing the appropriate folding before creating the outer C_MAYBE_CONST_EXPR. Bootstrapped with no regressions on x86_64-unknown-linux-gnu. Applied to mainline. Will apply to 4.7 (when not frozen) and 4.6 branches subject to testing there. c: 2012-09-14 Joseph Myers PR c/54552 * c-typeck.c (c_cast_expr): When casting to a type requiring C_MAYBE_CONST_EXPR to be created, pass the inner expression to c_fully_fold first. testsuite: 2012-09-14 Joseph Myers PR c/54552 * gcc.c-torture/compile/pr54552-1.c: New test. Index: c/c-typeck.c =================================================================== --- c/c-typeck.c (revision 191305) +++ c/c-typeck.c (working copy) @@ -4779,8 +4779,11 @@ c_cast_expr (location_t loc, struct c_type_name *t ret = build_c_cast (loc, type, expr); if (type_expr) { + bool inner_expr_const = true; + ret = c_fully_fold (ret, require_constant_value, &inner_expr_const); ret = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (ret), type_expr, ret); - C_MAYBE_CONST_EXPR_NON_CONST (ret) = !type_expr_const; + C_MAYBE_CONST_EXPR_NON_CONST (ret) = !(type_expr_const + && inner_expr_const); SET_EXPR_LOCATION (ret, loc); } Index: testsuite/gcc.c-torture/compile/pr54552-1.c =================================================================== --- testsuite/gcc.c-torture/compile/pr54552-1.c (revision 0) +++ testsuite/gcc.c-torture/compile/pr54552-1.c (revision 0) @@ -0,0 +1,8 @@ +void +f (void) +{ + unsigned n = 10; + + typedef double T[n]; + (double (*)[n])((unsigned char (*)[sizeof (T)]){ 0 }); +}