From patchwork Wed Dec 6 20:32:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1872957 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=ih1LOBh0; 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 4SlpxF07jWz23nW for ; Thu, 7 Dec 2023 07:32:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D307238582B1 for ; Wed, 6 Dec 2023 20:32: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.20]) by sourceware.org (Postfix) with ESMTPS id 2BB433858D39; Wed, 6 Dec 2023 20:32:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2BB433858D39 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 2BB433858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701894739; cv=none; b=B6qS7AlPQxfzN/JM1xvjOjJg1dydfGQ4c8AINEJE2cTFZ7R6mS6R/pmSfHXwjJlGaEtBnSvqHBFo/tUdRBrn8KWr0U6LQOyA1RetxC7JOAOlUifTeoD3gDLBU9z5DzDlRvdbm/PBbdpOcyGgmU89x96DNKeWjwsdogNmz8Q19Ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701894739; c=relaxed/simple; bh=5tyPHF/BGmNzit6QmR8/Im7JoGiz1yrLXU3Fo4nYOhQ=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=OUo9N63X2Lkv3aO0YPZ8iBWPs0Fs+vrqkHhi8oYRD2+aXTsN04W1cFwGuDC/IwLdT/UG1aftL6XQ6CKFRHM6aCnZOSICO/KDWynqSVqghmlyj5SatiLCU4icLbHT+mGkbGWoAloXJgL/RJj5T93ZTrbNJuH0Nc9QIAe+hfZgzjU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1701894736; x=1702499536; i=anlauf@gmx.de; bh=5tyPHF/BGmNzit6QmR8/Im7JoGiz1yrLXU3Fo4nYOhQ=; h=X-UI-Sender-Class:From:To:Subject:Date; b=ih1LOBh0aDeToPywgACrfHlEJOB0KqO8sdn+M9bmEdFDHESdltchEe0grG1Fx4ay QIiES5hwiD5F3EzUvWLCsmoyDFGair/IEiYuHw75x1zuKppBp/LoeAQnTNoRwtjJ2 6xLGXgZGw6L4xR6THlEUQ+Mj7JrQiU/XMeB/6YV+3yvY+IR8MIrlSHE6KuuaHdhcA 4efHE0z7DnHLEXPiPCenSZV3TbLDH25H3DN5SHPErLG8NziYKuCAN/3cvn/y8Rt/Y qKGIeL7U3HMAj3w9oyR3IXFlM8Ulr19oI2iOHBdedbyyaJRz+oVB3x5fowSIfZhdN rvVd9xQZItQGpmRt5g== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.7.237] ([79.251.7.237]) by web-mail.gmx.net (3c-app-gmx-bap48.server.lan [172.19.172.118]) (via HTTP); Wed, 6 Dec 2023 21:32:16 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: function returning contiguous class array [PR105543] Date: Wed, 6 Dec 2023 21:32:16 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:Pb2PFgdDjIO4YXshA9ahu3UStndUVBhSeBJfQ7n/T8O6pGkgC1e8cLcxGSeNSZiDPLite QkwjKz7Uf7Qy4z2/1L3AzBGyAH9EieJbjJ8GB7koVm6AU6oAN+gUMUCQ982DCZlx4gqp8+dl3lLY pQ6+OvQq7yDPqvZ7zfNxtDSY9Q8x6X/wu2VaDgRxCyzWOCJ8x2tW+ZLnxeuvViROxXfLyqCOLi8+ aZAI+XuTaJNE0RJWKPIQbQZrce6vQpdOn+dvAJ9TZNBfdkfrgZQyfwIaDUi8YTqwniA030biPqz0 iA= UI-OutboundReport: notjunk:1;M01:P0:yI/ABDGdnbE=;htovx65BI2foQmHGb/gcwKMj4Ff 9kb80v1sTO2urlP1X4KLkaBUVrqwz+OCHMgxh6tgzOL1F9IUNZyVEqsrlD6bcElN+I0hHsdou Y4zzxzQpYo7PH2877sb8rIQH7e9rjbBF0Z1xKHDXUzVtx97kU5xnOATvv34Utk+lpPNFRcNF5 FUu9/x7YHAiRYExGa4MJsQsV1ydiezuntdz6JisclNxYrFX4pup09TzQwSeVJOF+F6QqzfQyC 3EhTkmTOs3ySYKtRBw1hEJHYGDPIrpXZNuSrB4yaJvzrWLz7EO4Pr604zv48q41X4d8wJCohM Js41Nci+2kSrhX4t8zws9rMrU6omjJXVid/waAqojSbQTzLdiF9HfybEgMsWHFjWLj815shTk Jh+2TKxZPn/qQDWKXdxoewXVYaoGM8gQcrwzr+Mr2iRLZ8JSbumtdcebu9+tCCj/o+f4fwAbF tb79Y+krVq1bZd5CQqShvzbqd12wpv2bn+gfdMtUFCeMGRf2YzH4i7GlY2JV2RvDf/B334uvz U1y/rhYQCku+rAvs2B3WTNALYc3gznXSK/0ubYZasz88fmPoLQqjAoqdbxTwmNj+K2fw7h1pJ k+2fLg7388AH+jZAAkdyum0Ouw+kPkhAwc7VO0GnS0euzOn3/KlXLZe1/OLsQ3oHZ9rFF1M0G nHx8lq8Y4NSJH1+xsJx/htg80UQut2ZJNwyO54LHC7Qy/oNju4KEpqJFEdli3ka/DGL0725me Nc9EC6WPJYhj6Ods7pY7/i2bVx7UZPMXL01Ylq1TAAoUgl0AdODPL4dOUFxmC2ik/vTto9hPe 3KqBLoXNpkpnbnO2EVTJfjUYcHjkkvL6SdJdySWjPngT0= X-Spam-Status: No, score=-11.8 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_H4, RCVD_IN_MSPIKE_WL, 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 patch fixes a rejects-valid for functions returning a contiguous CLASS result. The problem occurs because attr.class_ok is inconsistent between sym and sym->result at the time the check of the contiguous attribute is done. I first thought that resolve_fl_procedure would be the right place to do this fixup, but this is invoked only later from resolve_symbol. Another attempt to put a fix directly after the recursive call to resolve_symbol for sym->result lead to frightening regressions in the testsuite, so I stayed with the attached simple solution. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 15810999b2f5cb4d8fbdaaaa69cb488c9b0c58e6 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 6 Dec 2023 20:42:27 +0100 Subject: [PATCH] Fortran: function returning contiguous class array [PR105543] gcc/fortran/ChangeLog: PR fortran/105543 * resolve.cc (resolve_symbol): For a CLASS-valued function having a RESULT clause, ensure that attr.class_ok is set for its symbol as well as for its resolved result variable. gcc/testsuite/ChangeLog: PR fortran/105543 * gfortran.dg/contiguous_13.f90: New test. --- gcc/fortran/resolve.cc | 5 +++++ gcc/testsuite/gfortran.dg/contiguous_13.f90 | 22 +++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/contiguous_13.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 166b702cd9a..4fe0e7202e5 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -16102,6 +16102,11 @@ resolve_symbol (gfc_symbol *sym) specification_expr = saved_specification_expr; } + /* For a CLASS-valued function with a result variable, affirm that it has + been resolved also when looking at the symbol 'sym'. */ + if (mp_flag && sym->ts.type == BT_CLASS && sym->result->attr.class_ok) + sym->attr.class_ok = sym->result->attr.class_ok; + if (sym->ts.type == BT_CLASS && sym->attr.class_ok && sym->ts.u.derived && CLASS_DATA (sym)) { diff --git a/gcc/testsuite/gfortran.dg/contiguous_13.f90 b/gcc/testsuite/gfortran.dg/contiguous_13.f90 new file mode 100644 index 00000000000..8c6784432c9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/contiguous_13.f90 @@ -0,0 +1,22 @@ +! { dg-do compile } +! PR fortran/105543 - function returning contiguous class array +! Contributed by martin + +module func_contiguous + implicit none + type :: a + end type a +contains + function create1 () result(x) + class(a), dimension(:), contiguous, pointer :: x + end + function create2 () + class(a), dimension(:), contiguous, pointer :: create2 + end + function create3 () result(x) + class(*), dimension(:), contiguous, pointer :: x + end + function create4 () + class(*), dimension(:), contiguous, pointer :: create4 + end +end module func_contiguous -- 2.35.3