From patchwork Thu Dec 5 08:10:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1204520 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-515192-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="Qbbo3Jp2"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="URYAUfnu"; 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 47T7hH4W8nz9sP6 for ; Thu, 5 Dec 2019 19:10:53 +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 :content-transfer-encoding; q=dns; s=default; b=Sr0Obhj9VLUrbTfs Caalc5+fEpsLAcsGVFmXgJ6lGBwIouRqqWG+iDYkjSTbQoqGM7OlitFSZzl0V1Ln ZvQGd15PP2CZjPSIn6f9c88xHLZotUMRCx9KCOcb9y64niyF4HZWzaPgWqaUYtDH cIecA1Vs00ei59zH1LsNuMbxyg8= 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 :content-transfer-encoding; s=default; bh=cBsRrDe49QW/zKUJU7xLuM PlufU=; b=Qbbo3Jp21pr6ngFEn1DmJRY4T9ybKkqUIv8wnxQk0JL/FmWLl6rWw+ JJwQcPaAGoyPzy7Q5151cUgJZlt2RLQDzWAx4TXFaGIigfIb5HS2A76SiK3ixt78 dPQHRFiV8d2DQvrmpDOYPamKQFe5FSggo67MWZZHQ8xNqVijetY94= Received: (qmail 124454 invoked by alias); 5 Dec 2019 08:10:45 -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 124432 invoked by uid 89); 5 Dec 2019 08:10:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-7.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: us-smtp-1.mimecast.com Received: from us-smtp-delivery-1.mimecast.com (HELO us-smtp-1.mimecast.com) (205.139.110.120) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Dec 2019 08:10:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575533442; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ocsOl3Do1x8wIHGsnk4e/EBoouGwHN0b/PuHc14pPlI=; b=URYAUfnu4ydSn/cwumgF9+Z4g0QXD90NDK6jXr3n4+TUbd0qE3Tp5dNvpcKnqybJS98sCi gGQ18urZRuOeGjmmqnOIbUUKZXAVAS8+ECihs4P532sPhucY45yVrlhz8F0hqHmmsZnzkn SA/pT+g2tHh/qNF9jCLD0uQpB8KfGUM= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-246-Iky8AO-OOlqTIBZjtwsVbQ-1; Thu, 05 Dec 2019 03:10:40 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E509318557C2; Thu, 5 Dec 2019 08:10:39 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-59.ams2.redhat.com [10.36.117.59]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7411D5DA32; Thu, 5 Dec 2019 08:10:39 +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 xB58Abm1024258; Thu, 5 Dec 2019 09:10:37 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id xB58AaRw024241; Thu, 5 Dec 2019 09:10:36 +0100 Date: Thu, 5 Dec 2019 09:10:36 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH] Fix Fortran ICE in tree-nested.c (PR fortran/92781) Message-ID: <20191205081036.GO10088@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Mimecast-Spam-Score: 0 Content-Disposition: inline X-IsSubscribed: yes Hi! In the following testcase, sym is the current function, we have created earlier .__result as the PARM_DECL containing pointer to the length to be returned and ..__result is a local VAR_DECL which contains the string length inside of the function and is at the end copied to *.__result. The reason this ICEs in tree-nested.c is that DECL_CONTEXT of that automatic ..__result variable is NULL, rather than the expected context of the current function. This happens because we attempt to add it to the parent function (which there isn't any), so DECL_CONTEXT is NULL. The following patch fixes that, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2019-12-05 Jakub Jelinek PR fortran/92781 * trans-decl.c (gfc_get_symbol_decl): If sym->backend_decl is current_function_decl, add length to current rather than parent function and expect DECL_CONTEXT (length) to be current_function_decl. * gfortran.dg/pr92781.f90: New test. Jakub --- gcc/fortran/trans-decl.c.jj 2019-11-11 21:04:05.000000000 +0100 +++ gcc/fortran/trans-decl.c 2019-12-04 12:32:58.489578829 +0100 @@ -1631,15 +1631,18 @@ gfc_get_symbol_decl (gfc_symbol * sym) /* Add the string length to the same context as the symbol. */ if (DECL_CONTEXT (length) == NULL_TREE) { - if (DECL_CONTEXT (sym->backend_decl) - == current_function_decl) + if (sym->backend_decl == current_function_decl + || (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 (sym->backend_decl == current_function_decl + ? DECL_CONTEXT (length) == current_function_decl + : (DECL_CONTEXT (sym->backend_decl) + == DECL_CONTEXT (length))); gfc_defer_symbol_init (sym); } --- gcc/testsuite/gfortran.dg/pr92781.f90.jj 2019-12-04 12:42:39.063598013 +0100 +++ gcc/testsuite/gfortran.dg/pr92781.f90 2019-12-04 12:42:20.032891766 +0100 @@ -0,0 +1,11 @@ +! PR fortran/92781 +! { dg-do compile } + +function foo () + character(:), allocatable :: foo + call bar () + foo = 'abc' +contains + subroutine bar + end +end