From patchwork Mon Jun 3 20:12:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1943023 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=gmx.de header.i=anlauf@gmx.de header.a=rsa-sha256 header.s=s31663417 header.b=M7DCyEW7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VtPz52wM5z20Q1 for ; Tue, 4 Jun 2024 06:12:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD8DA3955614 for ; Mon, 3 Jun 2024 20:12:30 +0000 (GMT) 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.17.21]) by sourceware.org (Postfix) with ESMTPS id 51C483857C4F; Mon, 3 Jun 2024 20:12:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51C483857C4F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 51C483857C4F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717445532; cv=none; b=QPhQcR3x0nDi0wbbIxPnMaupEBg5ISVQJE3w3pB21XntPT811N0wtRF5S16uwFr3tisCnn0C0om1ccPfVv5E8n+jwE5imJ3ll+6OKsXQRbpU1QM2hyP0zQKVFMemD3ZcfHmIphwdww6EXCX/9werqLCrbH8Etisg7UlupKT5v6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717445532; c=relaxed/simple; bh=1OGlLjVWFz5kLIYsYkGEpyvfmcyMTgkEKx4vRrGjocQ=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=UhOkWifsOb/+h2rCJnuD1syRFlDuJBVhH0mX4d38vec0lllXMAg4d26Dgt4s8LdLwi/BD2KXsCUUALJRox0p3BWTzSxNiYMb2VU5niXV4/tawH/ZfsGSwKUl93gXWjVOuPrdJj07cETP7vCPqsURNh+V9oFADEkEVAnB39KshLI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1717445529; x=1718050329; i=anlauf@gmx.de; bh=/kO89HjUKSRqC5jRtJMxFyyzVFjE2x6pdbXKCD79BGM=; h=X-UI-Sender-Class:MIME-Version:Message-ID:From:To:Subject: Content-Type:Date:cc:content-transfer-encoding:content-type:date: from:message-id:mime-version:reply-to:subject:to; b=M7DCyEW72FlBKhth0LdhWzmKZAEK2Drpufdip7lhzO2VDjY/8Yerrx5YJ2nC20gA GF8BbSkT2LJAI0ER0LMGXakP7Q8F07nK70bZjk4GhyZivA/HTI/sXYZcmAyfr2Hwg BrigxRgGucwviwvNSj0IsWWEKVga9mNRHYseXnJFdGoo/op++qcpVNqVwOmODzOIi FqpTxwS0Ul1s8xgUaYTgL1l1r3ZVSPpQAWJ1/3fWDDxdLyLgDwz7lw3niBeCaD1/B 6ds289TzEw0fARJmZW/knOXUm9WGChi8js2BTqQ3YIkHzSiNC9qTBvxRZsxdqMBer VD1wQ+Rkid/nLml7kw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.232.151.231] ([79.232.151.231]) by web-mail.gmx.net (3c-app-gmx-bap34.server.lan [172.19.172.104]) (via HTTP); Mon, 3 Jun 2024 22:12:08 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: fix ALLOCATE with SOURCE=, zero-length character [PR83865] Date: Mon, 3 Jun 2024 22:12:08 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:IBTJVXgvydbypgbk3ZMsH6N3n98H94EdDbBl5wJ+c7ff1/bPA9+UOY460G7IyIyESYs2R LwV8bIykBZAaTvV4mYnYavgCr5sx1wd0FKiz9YXagy+UOiTaNZRURLxfWxoDTQxYR7k4TS/b3Ql/ VSQMJo5Y99MbU8y41je3lZqHcFo8qLAKGQvYHTg743CzifUwv4xVNmijAypwUcffVhur5JclmQeZ q9Mdh/Sg8S7QgbwAnximwhjm8f7UWz6/oijK3eFW+3a2bXYn0AwmjkaTACk5Agoiz5MkU0iOJAl+ s8= UI-OutboundReport: notjunk:1;M01:P0:0zS0MHZRgD4=;PA0ynmWP4o3iUFHbfeuw1UPVIDC 9BMHtIghCwDnYNc4qvLpJUkK9KzeJflBsmyuqq6Ropkc8yh0Qh5hzwpa3b1btpqJ4tQHfvMxP tZ1V10cAIlrl0y0W8H+O+I/c7l5MAOyJljL6v/rvNDSOvum/5TsVLmR+qcCawoayezPv8SYVY 5cklh/HyoFGXxXX1VRbFdZaNk8qi/iFT7hP2+/vtlQY0tMuvtlGhmtoPojq6sbiibymWQurzH uFItcTyG3gIkYOPMR5iWgUaY1p9rkm6cnc6L7Qr13HgHCiLAUq6S9dQuwcdig/jEd8a0NFX21 ObIBWXtpfeiL/Gt1fgD0iu+Iqx7gJKbQzqHBdOocTrATAgXYWd+mYMgbOugyDCsL9Y+C54Eqk wHLEbFZZEIxv1tBdEq2MvWyE9uGtnBgzhr6cgbXZ1jIIxB9lSYB3wAooiYWeZRsrOD+UomRne sj2duGrrEETkxMDsXFsdVi/ZB3aLC04Fo6wtvHSV2NZZIqgmS9Ub2xEGIhgA5+EZ+8BmNj87U vYvYTXvpKrIM0+5ck+j8IJn1gvIsll1ExsHxE/XpS4oI68ucii6Lihpwi/o39ZG0U05ZoquPU ZOye1pjrH8oF3aedUwGnoRtPzA3phGtrXUzNWrr7Wj0i7GByVbVo3/4AURvyvY8AoqYtuYNEt U8fqfKjGbKYnZRiPcUkCLVJSY1Md2Eo40HH2ZEa114XEmmlC+9A78QyeTCW9lBI= X-Spam-Status: No, score=-12.4 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, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Dear all, the attached simple patch fixes an ICE for ALLOCATE with SOURCE= of a deferred-length character array with source-expression being an array of character with length zero. The reason was that the array descriptor of the source-expression was discarded in the special case of length 0. Solution: restrict special case to rank 0. Regtested on x86_64-pc-linux-gnu. OK for mainline? The offending code was introduced during 7-development, so it is technically a regression. I would therefore like to backport after waiting for a week or two. Thanks, Harald From ae5e3654d30d17584cfcfc3bbcc48cf75cb7453c Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 3 Jun 2024 22:02:06 +0200 Subject: [PATCH] Fortran: fix ALLOCATE with SOURCE=, zero-length character [PR83865] gcc/fortran/ChangeLog: PR fortran/83865 * trans-stmt.cc (gfc_trans_allocate): Restrict special case for source-expression with zero-length character to rank 0, so that the array shape is not discarded. gcc/testsuite/ChangeLog: PR fortran/83865 * gfortran.dg/allocate_with_source_32.f90: New test. --- gcc/fortran/trans-stmt.cc | 3 +- .../gfortran.dg/allocate_with_source_32.f90 | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/allocate_with_source_32.f90 diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc index 9b497d6bdc6..93b633e212e 100644 --- a/gcc/fortran/trans-stmt.cc +++ b/gcc/fortran/trans-stmt.cc @@ -6449,8 +6449,9 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist *omp_allocate) else gfc_add_block_to_block (&post, &se.post); - /* Special case when string in expr3 is zero. */ + /* Special case when string in expr3 is scalar and has length zero. */ if (code->expr3->ts.type == BT_CHARACTER + && code->expr3->rank == 0 && integer_zerop (se.string_length)) { gfc_init_se (&se, NULL); diff --git a/gcc/testsuite/gfortran.dg/allocate_with_source_32.f90 b/gcc/testsuite/gfortran.dg/allocate_with_source_32.f90 new file mode 100644 index 00000000000..4a9bd46da4d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocate_with_source_32.f90 @@ -0,0 +1,33 @@ +! { dg-do run } +! +! PR fortran/83865 +! +! Test ALLOCATE with SOURCE= of deferred length character, where +! the source-expression is an array of character with length 0. + +program p + implicit none + character(:), allocatable :: z(:) + character(1) :: cc(4) = "" + allocate (z, source=['']) + if (len (z) /= 0 .or. size (z) /= 1) stop 1 + deallocate (z) + allocate (z, source=['','']) + if (len (z) /= 0 .or. size (z) /= 2) stop 2 + deallocate (z) + allocate (z, source=[ character(0) :: 'a','b','c']) + if (len (z) /= 0 .or. size (z) /= 3) stop 3 + deallocate (z) + allocate (z, source=[ character(0) :: cc ]) + if (len (z) /= 0 .or. size (z) /= 4) stop 4 + deallocate (z) + associate (x => f()) + if (len (x) /= 0 .or. size (x) /= 1) stop 5 + if (x(1) /= '') stop 6 + end associate +contains + function f() result(z) + character(:), allocatable :: z(:) + allocate (z, source=['']) + end function f +end -- 2.35.3