From patchwork Mon Jan 16 21:11:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 44321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1403224wrn; Mon, 16 Jan 2023 13:12:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXubSkVYBGB2E29VgqmaYECMcJqE/OEkpG6wt90jwcGFrYB6Vu9jEKZ/o+gfNYbQ8CDKGPBz X-Received: by 2002:a17:906:c1c6:b0:819:2756:e090 with SMTP id bw6-20020a170906c1c600b008192756e090mr364407ejb.50.1673903556405; Mon, 16 Jan 2023 13:12:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673903556; cv=none; d=google.com; s=arc-20160816; b=SOgvcoax9prfq0EfhSHq3EkH86l7JtYcBsw5HGVLj48UrugfnqOXvQpLZKe3cIrQ7i RtCAMw4ZJiVx+BzF3dXcb1LSmGAruz2PlGyerZxbcZlvm9r9SV8At81YVIDfFeMlt/Hu CO146+LrAmaPuMi5+Hqgw55ggzoVwYz8wSdejO3EszhhrgAzM0xZuAjUrFjpmel6JIN6 f1Pghg62R4tq9jkrDwSD8BYvcCPl50/78m5Y83J332eI12OoI9aTqiMeSKwoMB5bY/vX NQISLxag5yXXGeGZlfMgkxR8GAEAL1eN6I2pin8HiF6rBItyTzb8AJRGF4EGBBJ8DIXQ m5Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xrxCkTKAOQnHoZ5XdOTpR0VcnABXRQ71y/LPGxcY4SY=; b=uMnsXVblscuBq1A93WbyvhqJn6z1mMQCLshC43jNbavXcpT9MLkA0NTahdcAoySnSU WiDWa8vb252WiY2GH+aJfsEtDPeK7gFVeq+DDtgVh4xG1myPP4PbjQfs9sLK/uxY3Vai ENNEwgUh2e6ByCplEQcoL4XCEhh+MwZCV0kHM89XfRHhrhMGZHiH0jO27QJyT3caYIyY 6btltm9CqapAvs+I49xr4E4BuIavWRqcN17xd9iHrFfwkzqi4GLXRSvJdTRb0bUiUyBk kaV8gQM325lHCsEu/w3nOXcRaCFDns4V8RHpRRr2+nwwSKRCw7E0Edya8n8iQVe68rtQ ze0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nRwG4kcs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ck17-20020a170906c45100b00870729e3e1asi3675527ejb.467.2023.01.16.13.12.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Jan 2023 13:12:36 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nRwG4kcs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E45E3858C2B for ; Mon, 16 Jan 2023 21:12:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5E45E3858C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673903554; bh=xrxCkTKAOQnHoZ5XdOTpR0VcnABXRQ71y/LPGxcY4SY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=nRwG4kcskbO4N8afl73M9Os8PHmuWZZwyAgH5o6qrfQ+fA4cyhw9Kv6HfI9pmi9Od TomQnItYwJNp4X01vZo+9D9dslP4h+PBLpw3G4F8TwFIdAoZaAeAktvQGix1zK9+3f y6fx2JP7d9hzVe8l29LkvXGCs4fAuAFnf/ugkCaU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by sourceware.org (Postfix) with ESMTPS id 565FA3858D33; Mon, 16 Jan 2023 21:11:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 565FA3858D33 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.89.104] ([93.207.89.104]) by web-mail.gmx.net (3c-app-gmx-bs50.server.lan [172.19.170.103]) (via HTTP); Mon, 16 Jan 2023 22:11:49 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: fix ICE in check_charlen_present [PR108420] Date: Mon, 16 Jan 2023 22:11:49 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:GHu9yl8YnJEucga9e8lUKaK7iaGKoPPS+uVf9iXAoy9bwc9iAq+KHMEt3K8W3nAk4qOzf lyOePQvq0K20Q0nChHaLRKH62VV2PpXvWGzkOeq6ndyCPGVF3Fx5GY3Bdv2Jr370+RGh+Btlp2B/ QH+eU5uot3bttGnx6Fn/umnynJgfiCNMSofzz4d7a1wVaF8KF+nffbICKm/8w4tR8vxk6qE/YTmp qyfAxPvMhArwA3HITxIbvoMYnSreMPCwARPLQroLwZwoCbYdBd5hj+7Zhtgh6gmtvrjSPqV4rxa5 lA= UI-OutboundReport: notjunk:1;M01:P0:fBePYigY82Q=;XkkBqU54bY3b5p+DGekZLSJEduO OiYiOWHag3bx5tR62Mxvn6kkxaGnbqtoEzVJ+85zMf4L9pB5LJBKl/ju+pyuah3XHOUc2DTRb bwu4ZsQUhZ6z2TynEO0epl94iASD89oarFBTm/dHlVKzmMFNJKz511zCIsTFw7qJsIDm5vpwS UuOXj0eJjfw+tbfY74Q9SAuWvpdwGKsfyLYH9XAbFe5elxf/RzQdh+Pxi9DZ3qexnaCVa2ixf 4jXPHoormO8Dba+6p5zR8V4g047Ixvk4hJLIeOTAgFaV2roxvAfPhvvBR1ZSLcL7zRXo44ruY OUZzpNBXZezBfidWcipbSCa8v2tq7SJa9psnl2+jtGRXk1BdwZqeqQy9uVnXJtM65WAZdBgre a6SEJOuoQJJLnSGjZ5uo3Rq0Giz8bb14t7j7/zHjerOykQBNZOAoJc+r5QmuRRzW6FmWzvf7Y 0GfaPYZKGpxU+QUf5A2Cs/hF4JxpU7moDK52vR0Ngm5gyHFNjNA4uGSvbhWpwdH+aPUl/c6wy F+328xFn/9eR7MPNtcKTqrI2n2PDvKkbKLX8ikAK42vLFB1kITptQB8N/eLqThpfwqMEqwEld XfEbwveuLUppcd6GKUCoO+5M9a3WxhRUaIhsLaW63yqbt266Bck6KNhakxRxyrz1DsjuGiPzk 1HztcbmDj0safMbsHdrN5tpm2+bN2uwqPNxc6kAIPApGQRtYKZgj8PY8dxIGTX7XxvSow9AUf BnjGcFNK1UXuBI33aMAVWFv0Iq7KueHKmwcenk/DPgbQtD8pmoGLPGbprNGHxE0KGNVZufax4 7K56wEl4RYsR/liPx2BOIhqQ== X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755215095671423738?= X-GMAIL-MSGID: =?utf-8?q?1755215095671423738?= Dear all, it appears that the fix for pr107874 uncovered a latent bug for the case of arrays of type character and size zero when passed to the intrinsics MERGE and SPREAD as SOURCE. In that case, there is no constructor from which we could obtain another character length. A reasonable solution seems to retain the array's character length. Since I could not find a simple case where this fails, I've added an assertion that we actually have a meaningful length. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From a4fbab560a202f4541f8f9a872774b2cbf72b4b0 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 16 Jan 2023 21:41:09 +0100 Subject: [PATCH] Fortran: fix ICE in check_charlen_present [PR108420] gcc/fortran/ChangeLog: PR fortran/108420 * iresolve.cc (check_charlen_present): Preserve character length if there is no array constructor. gcc/testsuite/ChangeLog: PR fortran/108420 * gfortran.dg/pr108420.f90: New test. --- gcc/fortran/iresolve.cc | 9 ++++++--- gcc/testsuite/gfortran.dg/pr108420.f90 | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr108420.f90 diff --git a/gcc/fortran/iresolve.cc b/gcc/fortran/iresolve.cc index 711e9178ad4..33794f0a858 100644 --- a/gcc/fortran/iresolve.cc +++ b/gcc/fortran/iresolve.cc @@ -94,9 +94,12 @@ check_charlen_present (gfc_expr *source) else if (source->expr_type == EXPR_ARRAY) { gfc_constructor *c = gfc_constructor_first (source->value.constructor); - source->ts.u.cl->length - = gfc_get_int_expr (gfc_charlen_int_kind, NULL, - c->expr->value.character.length); + if (c) + source->ts.u.cl->length + = gfc_get_int_expr (gfc_charlen_int_kind, NULL, + c->expr->value.character.length); + if (source->ts.u.cl->length == NULL) + gfc_internal_error ("check_charlen_present(): length not set"); } } diff --git a/gcc/testsuite/gfortran.dg/pr108420.f90 b/gcc/testsuite/gfortran.dg/pr108420.f90 new file mode 100644 index 00000000000..985c0b3bf53 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr108420.f90 @@ -0,0 +1,10 @@ +! { dg-do compile } +! PR fortran/108420 +! Contributed by G.Steinmetz + +program p + character :: c = 'c' + logical :: m = .true. + print *, merge(transfer('a', 'b', 0), c, .true.) + print *, merge(transfer('a', 'b', 0), c, m) +end -- 2.35.3