From patchwork Wed Feb 15 09:07:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Bruel X-Patchwork-Id: 141282 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 757431007D4 for ; Wed, 15 Feb 2012 20:44:27 +1100 (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=1329903868; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Message-ID:Date:From:User-Agent:MIME-Version: To:Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=Mc4qdPhFjPzEBfL7EvgCS/fjyZg=; b=H5OA+ll0rTeB/Fi NhKhSnf0dTo0LR3XXZ00e2vWJ666pmQOaHXdpUqMStS+7q5LMqXo82Ac+TNdKMHD yb8rhGr/aBVJpI13HrCqI0AOnG9Pj19DNT6t+njT8uU59yxqQYriF/16Z7bNoVfc hC+AZkXDCqng1hiW/0r3TPjKSLpU= 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:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=AhxZF3sqlgfotJE6w7R/tTXClU524CU672/khZnPqhJ0A0fFcFjf8ZSysbFgL/ O3+L43xI3MLiOBslFdlIDM+4NqYorSQbn1EKlLBV4TkHpDatdnkqfhTOW7pr5Xm1 Rby6GCJ+o0w3aqcUvIkOtisql/QEuT9itQyLgcVXAKsFY=; Received: (qmail 12984 invoked by alias); 15 Feb 2012 09:44:23 -0000 Received: (qmail 12974 invoked by uid 22791); 15 Feb 2012 09:44:22 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from eu1sys200aog111.obsmtp.com (HELO eu1sys200aog111.obsmtp.com) (207.126.144.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 15 Feb 2012 09:44:08 +0000 Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob111.postini.com ([207.126.147.11]) with SMTP ID DSNKTzt+Zpxl3i2efDBOWCVxIKDSksWBoGUE@postini.com; Wed, 15 Feb 2012 09:44:07 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8FF60F5 for ; Wed, 15 Feb 2012 09:44:05 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas6.st.com [10.75.90.73]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1A21E1C38 for ; Wed, 15 Feb 2012 09:44:05 +0000 (GMT) Received: from [164.129.122.89] (164.129.122.89) by webmail-eu.st.com (10.75.90.13) with Microsoft SMTP Server (TLS) id 8.3.192.1; Wed, 15 Feb 2012 10:07:42 +0100 Message-ID: <4F3B75DE.9030406@st.com> Date: Wed, 15 Feb 2012 10:07:42 +0100 From: Christian Bruel User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: Subject: [PATCH, 4.6 regression]. New error: case label does not reduce 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 Hello, This patch fixes a regression when folding a cast cond expression to a constant in case label. The problem came from the removal of the lines in c-common.c:check_case_value /* ??? Can we ever get nops here for a valid case value? We shouldn't for C. */ STRIP_TYPE_NOPS (value); so the check for INTEGER_CST) now fails. The NOP is stripped after folding in 'c_fully_fold' and recreated in the fly even if no change of type is needed (the constant's type was converted to an integer, same than the case's type). Removal of this NOP_EXPR if !CAN_HAVE_LOCATION_P fixes the problem. looks safe from my testing, because the loc is inserted using 'protected_set_expr_location', whereas no loc for a constant case doesn't seem to introduce new problems with the debugging information. But in case I also added a few paranoid gcc_assert. The motivating failing case is added in the attached testsuite part, The test now compiles and generates the expected error with -pedantic or -pedantic-error Bootstrapped/Regression tested on x86 Thanks for any comment, and if OK to go for 4.6 and trunk Many thanks Christian 2010-02-15 Christian Bruel * gcc/c-common.c (c_fully_fold_internal): Don't create a new NOP expr. * gcc/fold-const.c (try_move_mult_to_index): assert CAN_HAVE_LOCATION_P. (fold_comparison): Likewise. * gcc/tree.c (build_case_label): Likewise. Index: c-family/c-common.c =================================================================== --- c-family/c-common.c (revision 184254) +++ c-family/c-common.c (working copy) @@ -1435,12 +1435,9 @@ have been done by this point, so remove them again. */ nowarning |= TREE_NO_WARNING (ret); STRIP_TYPE_NOPS (ret); - if (nowarning && !TREE_NO_WARNING (ret)) - { - if (!CAN_HAVE_LOCATION_P (ret)) - ret = build1 (NOP_EXPR, TREE_TYPE (ret), ret); - TREE_NO_WARNING (ret) = 1; - } + if (nowarning) + TREE_NO_WARNING (ret) = 1; + if (ret != expr) protected_set_expr_location (ret, loc); return ret; Index: tree.c =================================================================== --- tree.c (revision 184254) +++ tree.c (working copy) @@ -1678,6 +1678,7 @@ tree t = make_node (CASE_LABEL_EXPR); TREE_TYPE (t) = void_type_node; + gcc_assert (CAN_HAVE_LOCATION_P (t)); SET_EXPR_LOCATION (t, DECL_SOURCE_LOCATION (label_decl)); CASE_LOW (t) = low_value; Index: fold-const.c =================================================================== --- fold-const.c (revision 184254) +++ fold-const.c (working copy) @@ -6972,6 +6972,7 @@ pref = TREE_OPERAND (addr, 0); ret = copy_node (pref); + gcc_assert (CAN_HAVE_LOCATION_P (ret)); SET_EXPR_LOCATION (ret, loc); pos = ret; @@ -9427,6 +9428,7 @@ if (save_p) { tem = save_expr (build2 (code, type, cval1, cval2)); + gcc_assert (CAN_HAVE_LOCATION_P (tem)); SET_EXPR_LOCATION (tem, loc); return tem; }