From patchwork Thu Jan 2 22:35:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1217159 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-516595-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=netcologne.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="KedEamlc"; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.b="Tm5mYTdX"; 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 47pjYm5mH5z9sVN for ; Fri, 3 Jan 2020 09:36:10 +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:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=VhEGqa0hb6eMpGL8qJjoGlUSbnS3Adbwq9KvZgcxCPYlq3P925 /g2Rrj2327hJw6/QnAkVDutrb/+Ig3YpBTaedHoGZ8i4VFkK8PSAWNrGCWqt+583 kBTPAphWsUbzjCMigeXiSNVADqfbVwCCsX2sLUL9N2PbIu1mRuUfa0+qc= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=PD5atxsAKHDC1tW3cN4Maaw3awk=; b=KedEamlcTV2PwFEFFCUO QmHLxLvfSIkkMZvd36Ah/00B3itnNRy8aNIN0n7k8OzUTwtKpzQuqBjV4+UM6zVy XbqxVEn4nhkbYnY9gTie5EAPFu4fcmvDZSbUIUYDU1nPykwQJ5VJj/6u6n4trUJ+ 8tj0r3o11/tQMn+MSSKpmFc= Received: (qmail 77282 invoked by alias); 2 Jan 2020 22:35:59 -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 77262 invoked by uid 89); 2 Jan 2020 22:35:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: cc-smtpout3.netcologne.de Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Jan 2020 22:35:56 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 3B4DE12482; Thu, 2 Jan 2020 23:35:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1578004553; bh=WuDgV4movGP4UFpeYnCnQCSJQE/R/9ogtGene0BYjIU=; h=To:From:Subject:Message-ID:Date:From; b=Tm5mYTdX+xeMlZjcLw1Rk3MHjTKg3r02xQ5Vo3FMWSjx9g0WV/g0yXeYbkb50yAiR PoBbP6Gqh+e/ru0ExgCf2WyTC8cKM18Gl+BxYTGM0FyvxHZ3lVzphSCvds9Wq8OEKc /vX1qo48yuzRRXycAFjINikTE1qiw5NlqxSiFYBKFmUsiYpGBvD5NDATtc6k4b36j4 rRxjaEGgh+gl4x6IIkWcq6Hx5+AhLzdfOM8747xPpbh5fgwmUm3ZH+xIUO8D6KtVTv BgorYzPQ4wKxXbrxg25sAszESWIaghZQevO9TSYyiH60Vtz2B0oaB3CseWrryeB2U1 iAvXw4ITQmJmA== Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 2E82711E04; Thu, 2 Jan 2020 23:35:53 +0100 (CET) Received: from [2001:4dd7:c1f2:0:4f93:57dc:bcf4:c716] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.11.6) (envelope-from ) id 5e0e7049-3658-7f0000012729-7f0000018612-1 for ; Thu, 02 Jan 2020 23:35:53 +0100 Received: from linux-p51k.fritz.box (2001-4dd7-c1f2-0-4f93-57dc-bcf4-c716.ipv6dyn.netcologne.de [IPv6:2001:4dd7:c1f2:0:4f93:57dc:bcf4:c716]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Thu, 2 Jan 2020 23:35:51 +0100 (CET) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Fix PR 65428, ICE on nested empty array constructors Message-ID: Date: Thu, 2 Jan 2020 23:35:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 Hello world, the attached patch fixes an ICE where an array constructor containing an empty array constructor with a type didn't get the type from the inner constructor. The solution is to stash the type away in yet another variable and only use it if the constructor turns out to be empty, and the type has not been set some other way. Regression-tested. OK for trunk? Regards Thomas Save typespec for empty array constructor. 2020-01-02 Thomas Koenig PR fortran/65428 * array.c (empty_constructor): New variable. (empty_ts): New variable. (expand_constructor): Save typespec in empty_ts. Unset empty_constructor if there is an element. (gfc_expand_constructor): Initialize empty_constructor and empty_ts. If there was no explicit constructor type and the constructor is empty, take the type from empty_ts. 2020-01-02 Thomas Koenig PR fortran/65428 * gfortran.dg/zero_sized_11.f90: New test. Index: array.c =================================================================== --- array.c (Revision 279821) +++ array.c (Arbeitskopie) @@ -1759,7 +1759,12 @@ cleanup: return t; } +/* Variables for noticing if all constructors are empty, and + if any of them had a type. */ +static bool empty_constructor; +static gfc_typespec empty_ts; + /* Expand a constructor into constant constructors without any iterators, calling the work function for each of the expanded expressions. The work function needs to either save or free the @@ -1782,6 +1787,9 @@ expand_constructor (gfc_constructor_base base) e = c->expr; + if (empty_constructor) + empty_ts = e->ts; + if (e->expr_type == EXPR_ARRAY) { if (!expand_constructor (e->value.constructor)) @@ -1790,6 +1798,7 @@ expand_constructor (gfc_constructor_base base) continue; } + empty_constructor = false; e = gfc_copy_expr (e); if (!gfc_simplify_expr (e, 1)) { @@ -1873,6 +1882,8 @@ gfc_expand_constructor (gfc_expr *e, bool fatal) iter_stack = NULL; + empty_constructor = true; + gfc_clear_ts (&empty_ts); current_expand.expand_work_function = expand; if (!expand_constructor (e->value.constructor)) @@ -1882,6 +1893,13 @@ gfc_expand_constructor (gfc_expr *e, bool fatal) goto done; } + /* If we don't have an explicit constructor type, and there + were only empty constructors, then take the type from + them. */ + + if (constructor_ts.type == BT_UNKNOWN && empty_constructor) + e->ts = empty_ts; + gfc_constructor_free (e->value.constructor); e->value.constructor = current_expand.base;