From patchwork Mon Nov 5 21:16:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 197309 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 2D4322C00A5 for ; Tue, 6 Nov 2012 08:21:13 +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=1352755274; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version: Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=IdTeMCneCdNToucvF56dkavxQvE=; b=tCoQ6g3l2qWjfd/ d8eB7QPTMeKeSBldboBWrR9ip5yNQ8l2mXNeyWOS5VledH541DYMhs6FJVRqp1HE +GO+CA2x7wI5MAlWPFZAair3AxPPysonc//4IdjHKW34YIN8WJ+GqlWb9OLE9OOU wHA4k16Mx6BgT/AjHqq79kh5uZKk= 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:From:To:Subject:Date:Message-ID:User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=CZ8Q9bPMpx3h8o5XUR5w6Cfcx6WqxgowHksRxpzsOxm4iAsn/LdeiV3BA9R+2r 075vJfsTXMqgoVS5YUw9jIxWITz9b1qYj6LLw6O6YCl/MTBSxhXwc7w2mYl2BSFz JCVdNcGZn6ZrIMYJdbUz77ZmqlzcNvsxUV0hpp4GPvVNM=; Received: (qmail 14265 invoked by alias); 5 Nov 2012 21:21:08 -0000 Received: (qmail 14257 invoked by uid 22791); 5 Nov 2012 21:21:07 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 05 Nov 2012 21:20:59 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 79453CB03B1 for ; Mon, 5 Nov 2012 22:20:59 +0100 (CET) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jusBe2FEsL8b for ; Mon, 5 Nov 2012 22:20:59 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mel.act-europe.fr (Postfix) with ESMTP id EC209CB01DC for ; Mon, 5 Nov 2012 22:20:58 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Fix PR tree-optimization/54986 Date: Mon, 05 Nov 2012 22:16:31 +0100 Message-ID: <6178668.1GMYr7Gxhl@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.16-desktop; KDE/4.7.2; x86_64; ; ) 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 Hi, this is a regression present on the 4.7 branch and caused by my fix for another regression: http://gcc.gnu.org/ml/gcc-patches/2012-07/msg00825.html It turns out that canonicalize_constructor_val has side effects: on the 4.7 branch, it calls add_referenced_var on the base variable of an address (it does something similar on mainline) and not calling it for the testcase leads to a segfault later because the var_ann of a global variable doesn't exist. So the STRIP_NOPS is needed for the pattern matching code to work. That's why the attached patch adds it back but makes it so that an appropriate cast is added back at the end if necessary. Bootstrapped/regtested on x86_64-suse-linux, OK for mainline and 4.7 branch? 2012-11-05 Eric Botcazou PR tree-optimization/54986 * gimple-fold.c (canonicalize_constructor_val): Strip again all no-op conversions on entry but add them back on exit if needed. 2012-11-05 Eric Botcazou * g++.dg/torture/20121005-1.C: New test. Index: gimple-fold.c =================================================================== --- gimple-fold.c (revision 193090) +++ gimple-fold.c (working copy) @@ -139,7 +139,8 @@ can_refer_decl_in_current_unit_p (tree d tree canonicalize_constructor_val (tree cval, tree from_decl) { - STRIP_USELESS_TYPE_CONVERSION (cval); + tree orig_cval = cval; + STRIP_NOPS (cval); if (TREE_CODE (cval) == POINTER_PLUS_EXPR && TREE_CODE (TREE_OPERAND (cval, 1)) == INTEGER_CST) { @@ -182,8 +183,12 @@ canonicalize_constructor_val (tree cval, /* Fixup types in global initializers. */ if (TREE_TYPE (TREE_TYPE (cval)) != TREE_TYPE (TREE_OPERAND (cval, 0))) cval = build_fold_addr_expr (TREE_OPERAND (cval, 0)); + + if (!useless_type_conversion_p (TREE_TYPE (orig_cval), TREE_TYPE (cval))) + cval = fold_convert (TREE_TYPE (orig_cval), cval); + return cval; } - return cval; + return orig_cval; } /* If SYM is a constant variable with known value, return the value.