From patchwork Fri Jun 28 20:00:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1954155 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=YsiQ/l1q; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4W9mXl1hMfz1yhT for ; Sat, 29 Jun 2024 06:01:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A8F983892459 for ; Fri, 28 Jun 2024 20:01:22 +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.15.18]) by sourceware.org (Postfix) with ESMTPS id 703373826DDF; Fri, 28 Jun 2024 20:00:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 703373826DDF 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 703373826DDF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.15.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719604857; cv=none; b=mXTZbqHuZTwvZ/rEJCgeDqzlws4lDxoBS7xwKlmTze43nmU43CbmcU1tbjaBZP7qFwUWhix4fzKtrRZ56KMfnzsQFDPvvUl6yfrd3+PglvsA3yfGuHMKHqWfKmiFHvCQ/Xt7lnG+JuRe73HfpIqxDwQz8MPExmX0c9ATlIi4RQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719604857; c=relaxed/simple; bh=uVZfL0jp6NxoDpggZCmTmeswsicuNJzFn1LwJOU99t4=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=R15WZkaFUT0aCloqYT/ggDPEgJPwa52jqgxktjj2xSYFNU2d0qbdJdT8eJlZ1spCC3gB8uPEVTfE/dUiP5CP/XtjqIHCjx0WntJFWgdPNn932qESAUj5IpoRHd3AVxssH3PEVedyllfCn5pD3h8qiJz5PvgFjyVbLQpGe8POyF4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.de; s=s31663417; t=1719604853; x=1720209653; i=anlauf@gmx.de; bh=G579kqpkTOc4eZKrAk40QLiET4ulImTx/Y/BYLuOXRM=; 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=YsiQ/l1qXdhY71uogdntwkbQ+XdAzNUCVsAMZCF6WyPhZFeK+3Yc3JoZyNP5J31q ZOJDgC3gQp0YMXA9he+Zt1g+yFTHQRb88uD3mQrElsPPk/kfDrOoseSWukDOyHBOG JQ2yp+8CsySA09LMln3jQKJohmeOPjQ3mnfLqpsMp8CZrpdwGGH6wnmIgG1uPCTYw WabWItulD2EpeMnm+vyzaAGWwYRBAyovYfVxCTEvxCSrTctSWJKRRo0E7nphms4y2 QGcile9Fv+il+gYTaw+K2OKRYhaPBGnTysfidXn8EdkDAKHBJ5mKsOOQO3dxuEZQ2 kVzv6NCSoqEurEXJxQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.13.158] ([79.251.13.158]) by web-mail.gmx.net (3c-app-gmx-bs26.server.lan [172.19.170.78]) (via HTTP); Fri, 28 Jun 2024 22:00:53 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: fix ALLOCATE with SOURCE of deferred character length [PR114019] Date: Fri, 28 Jun 2024 22:00:53 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:/sI6NpbfCvzg6DTt4eVhFJNy+4XLdWk9ubNQvYyVPsA4u6h4xrDF4LY3Wgu3IdkYu5cPK Uv8QLDXR7evhpYsiGFgUs7YoRQDP911NrNpK9JrH29GgVxTczmHD/IPbdCmgW8n8bUbUJEuuUW9M qKo2gfFJfLs/Qq1r9ne8OqA4WYdY3Jb1YoCmAx7FDpct2KnsvVEu7fHpXK7yp2ArR1H/1oWqBYne qLHsyvzyhN2sSY7ooyugYoPXLWb8v8nkT11WIevktV9HzvZyEXlQn2q5QIhjxCAI1zGVVrhqjJC5 CA= UI-OutboundReport: notjunk:1;M01:P0:PtJlxT4Wwx4=;EPu1cmsaci0J56fTK4KtNpkQUXw 15E6AnGHCCG2Xsc01svoiJF2aM+Ho2vW/sx5IKxLQ56gJ0Kh5tHJLRhRKNupukvy3Mid2w4nJ ow2FPaC40I5quaSltGFJQsSQv8aOejPrWg5mzBmQadMys8So+/LV0C1KPY+itiExIlai/xXm2 x8WjGe2EiSAks8l1B7cfB3/93of0glBG5eWmI1pXrA45zoxrPMyJWRLtmY0AHf/PT8HZos9T2 dmrriS4KnxRroN7E5zcW7KW60CBAzufrhqFWgkEzibgaZ2leS7XyNLEgox6+LB5muswLKsDx9 HteuBtDZj2tcEMu0lACB/qJSFbCfWwEUspPk3weHMRxI4EgN+B08NcKPAb2vfd4Oovm58Genf k4juTLzSB5edavonjcLIo3FjbSqdCyFvk8dNGv6vmPfh1NMAeR66nojlatlxSrr2K+quO71Ss Ga0DOSRLy4frDsdVBfZcFvEaZ4xcaAZlioK3I11O0gr8BNT9byv/wUOOfNZ208h6BiIAqj6nb X/+JF6MLAhHL1TPYeVOP4vyRjNKRM66dZodCjMS5vhzp7frj70t7v9bbys9BVT5hipIBsCnFa Qb9QiERUTeIgwvgnwMAosJsQrGKom/d55obF+EQLo3Zogc9Eors/4GWzxnihqT/ACycwAE/dC ueyadDWJM3AnZiouMGLCBX8VVU+kUL3Oo0iohaA3F3YutrJheq8ZevPZ7Y9MZA0= X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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.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 patch fixes an ICE occuring for ALLOCATE with SOURCE (or MOLD) of deferred character length in the scalar case, which looked obscure because the ICE disappears at -O1 and higher. The dump tree suggests that it is a wrong decl for the temporary source that was e.g. character(kind=1) source.2[1:]; whereas I had expected character(kind=1)[1:] * source.2; and which we now get after the patch. Or am I missing something? Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 4d12f6d0cf63ea6a2deb5398e6478dde114e76b8 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Fri, 28 Jun 2024 21:44:06 +0200 Subject: [PATCH] Fortran: fix ALLOCATE with SOURCE of deferred character length [PR114019] gcc/fortran/ChangeLog: PR fortran/114019 * trans-stmt.cc (gfc_trans_allocate): Fix handling of case of scalar character expression being used for SOURCE. gcc/testsuite/ChangeLog: PR fortran/114019 * gfortran.dg/allocate_with_source_33.f90: New test. --- gcc/fortran/trans-stmt.cc | 5 +- .../gfortran.dg/allocate_with_source_33.f90 | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/allocate_with_source_33.f90 diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc index 93b633e212e..60275e18867 100644 --- a/gcc/fortran/trans-stmt.cc +++ b/gcc/fortran/trans-stmt.cc @@ -6464,7 +6464,10 @@ gfc_trans_allocate (gfc_code * code, gfc_omp_namelist *omp_allocate) else if (se.expr != NULL_TREE && temp_var_needed) { tree var, desc; - tmp = GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se.expr)) || is_coarray ? + tmp = (GFC_DESCRIPTOR_TYPE_P (TREE_TYPE (se.expr)) + || is_coarray + || (code->expr3->ts.type == BT_CHARACTER + && code->expr3->rank == 0)) ? se.expr : build_fold_indirect_ref_loc (input_location, se.expr); diff --git a/gcc/testsuite/gfortran.dg/allocate_with_source_33.f90 b/gcc/testsuite/gfortran.dg/allocate_with_source_33.f90 new file mode 100644 index 00000000000..7b1a26c464c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocate_with_source_33.f90 @@ -0,0 +1,53 @@ +! { dg-do compile } +! { dg-options "-O0" } +! +! PR fortran/114019 - allocation with source of deferred character length + +subroutine s + implicit none + character(1) :: w = "4" + character(*), parameter :: str = "123" + character(5), pointer :: chr_pointer1 + character(:), pointer :: chr_pointer2 + character(:), pointer :: chr_ptr_arr(:) + character(5), allocatable :: chr_alloc1 + character(:), allocatable :: chr_alloc2 + character(:), allocatable :: chr_all_arr(:) + allocate (chr_pointer1, source=w// str//w) + allocate (chr_pointer2, source=w// str//w) + allocate (chr_ptr_arr, source=w//[str//w]) + allocate (chr_alloc1, source=w// str//w) + allocate (chr_alloc2, source=w// str//w) + allocate (chr_all_arr, source=w//[str//w]) + allocate (chr_pointer1, mold =w// str//w) + allocate (chr_pointer2, mold =w// str//w) + allocate (chr_ptr_arr, mold =w//[str//w]) + allocate (chr_alloc1, mold =w// str//w) + allocate (chr_alloc2, mold =w// str//w) + allocate (chr_all_arr, mold =w//[str//w]) +end + +subroutine s2 + implicit none + integer, parameter :: ck=4 + character(kind=ck,len=1) :: w = ck_"4" + character(kind=ck,len=*), parameter :: str = ck_"123" + character(kind=ck,len=5), pointer :: chr_pointer1 + character(kind=ck,len=:), pointer :: chr_pointer2 + character(kind=ck,len=:), pointer :: chr_ptr_arr(:) + character(kind=ck,len=5), allocatable :: chr_alloc1 + character(kind=ck,len=:), allocatable :: chr_alloc2 + character(kind=ck,len=:), allocatable :: chr_all_arr(:) + allocate (chr_pointer1, source=w// str//w) + allocate (chr_pointer2, source=w// str//w) + allocate (chr_ptr_arr, source=w//[str//w]) + allocate (chr_alloc1, source=w// str//w) + allocate (chr_alloc2, source=w// str//w) + allocate (chr_all_arr, source=w//[str//w]) + allocate (chr_pointer1, mold =w// str//w) + allocate (chr_pointer2, mold =w// str//w) + allocate (chr_ptr_arr, mold =w//[str//w]) + allocate (chr_alloc1, mold =w// str//w) + allocate (chr_alloc2, mold =w// str//w) + allocate (chr_all_arr, mold =w//[str//w]) +end -- 2.35.3