From patchwork Fri Jan 18 22:42:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1027825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-494338-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="bTnPZdaD"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43hGCw1lynz9sDB for ; Sat, 19 Jan 2019 09:42:20 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=O9MErJOEPgCCOe04mSV9StyUo/Kq0eZPzAJ4DKP8r0/ zDQPUg33eWAzJKxbnEPkqlPHEHgdAay7V7dprFlNnlo2TKZR7M9fKWLXMtuMtDJo rpv4gQsil2eD7mgEqbM2BmqMJ6pWytXYvU6RYFOw0v1f8gl73qBZ1RsjeglfHQHM = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=b64UbgpHqeBDGq7nadDrmCD26zg=; b=bTnPZdaDJxXtAd43G cYQnKaN8ZhAcWdXLZ7cAWhlvylprOkWx55FQqjMOaQ5UXt2rDF73ZOszeQpHtU8j ts0nNqGtGLwtCW4dUOoHcspDhDmLJnIE/+BibtQCDl0yi6CGkufy5nZ1AgiWQ8g5 HHdA9KPVbpqgKu0vziMA0f7LFw= Received: (qmail 64048 invoked by alias); 18 Jan 2019 22:42:12 -0000 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 Received: (qmail 63998 invoked by uid 89); 18 Jan 2019 22:42:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 Jan 2019 22:42:10 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 34F888666E; Fri, 18 Jan 2019 22:42:09 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-69.ams2.redhat.com [10.36.116.69]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C540B60BE8; Fri, 18 Jan 2019 22:42:08 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x0IMg6iC013821; Fri, 18 Jan 2019 23:42:07 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x0IMg610013820; Fri, 18 Jan 2019 23:42:06 +0100 Date: Fri, 18 Jan 2019 23:42:06 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH] Fix LTO ICEs due to invalid self-referencing fortran character length VAR_DECL chains (PR fortran/88902) Message-ID: <20190118224206.GW30353@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-IsSubscribed: yes Hi! As the testcase shows, gfc_get_symbol_decl can be called multiple times and we can add the same length multiple times to current or parent function. As addition of a VAR_DECL to those is done by chaining it into the DECL_CHAIN linked list, adding the same VAR_DECL twice means a loop in the chain (in this testcase DECL_CHAIN referencing the containing VAR_DECL, but it could be longer loop). Any such loop is a bug and e.g. LTO is very upset about that. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-01-18 Jakub Jelinek PR fortran/88902 * trans-decl.c (gfc_get_symbol_decl): Don't add length to function or parent function if it has been added there already. * gfortran.dg/pr88902.f90: New test. Jakub --- gcc/fortran/trans-decl.c.jj 2019-01-16 09:35:08.000000000 +0100 +++ gcc/fortran/trans-decl.c 2019-01-18 13:03:07.073419557 +0100 @@ -1572,13 +1572,17 @@ gfc_get_symbol_decl (gfc_symbol * sym) if (VAR_P (length) && DECL_FILE_SCOPE_P (length)) { /* Add the string length to the same context as the symbol. */ - if (DECL_CONTEXT (sym->backend_decl) == current_function_decl) - gfc_add_decl_to_function (length); - else - gfc_add_decl_to_parent_function (length); + if (DECL_CONTEXT (length) == NULL_TREE) + { + if (DECL_CONTEXT (sym->backend_decl) + == current_function_decl) + gfc_add_decl_to_function (length); + else + gfc_add_decl_to_parent_function (length); + } - gcc_assert (DECL_CONTEXT (sym->backend_decl) == - DECL_CONTEXT (length)); + gcc_assert (DECL_CONTEXT (sym->backend_decl) + == DECL_CONTEXT (length)); gfc_defer_symbol_init (sym); } --- gcc/testsuite/gfortran.dg/pr88902.f90.jj 2019-01-18 12:58:03.738394429 +0100 +++ gcc/testsuite/gfortran.dg/pr88902.f90 2019-01-18 12:59:06.971357361 +0100 @@ -0,0 +1,6 @@ +! PR fortran/88902 +! { dg-do compile } +! { dg-require-effective-target lto } +! { dg-options "-flto --param ggc-min-heapsize=0" } + +include 'pr50069_2.f90'