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: 174742 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4400271vqy; Wed, 6 Dec 2023 13:54:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjtlJ9WMh598m22AnvBKnCae1D9SNNZT/B0Ze8kGr9qmoT40G2oRoCKHZGEuKMjXYsh9sE X-Received: by 2002:a05:620a:5634:b0:77d:84d1:a5a3 with SMTP id vv20-20020a05620a563400b0077d84d1a5a3mr246119qkn.20.1701899685457; Wed, 06 Dec 2023 13:54:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701899685; cv=pass; d=google.com; s=arc-20160816; b=Wq87nBKhMRHybZCJyR+1tzg06eAL8gKIVw4m9UoLVHyOhixFfCt+MCJ+okT9yt3OfF OsZk0eC5BRaDyHKyLu6/sel/9mDQ2AQiRaC4QSl4N3AtfQ2tWkMYzGfH44lFYRElG0Ud TUO5DdYL3DakxGoqHOOiw37/qcljCmbicoXrTDq9UlKOR0rTnjKipqJKNifpm+Hqld4L U5LBTWnlo6uPnKK6uV/2l7LJk7UevNZZNVvvjDoCJmH9sJfE6pGXHxnsitceiXjQECWA 3ZcuawLGXixLjQYKMtScaMgj89coLVdeME6Qs+jSQjmTdu8oiFTOVAO6kraq4Rf6/Jwc 1IMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:ui-outboundreport:sensitivity :importance:date:subject:to:from:message-id:mime-version :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=5wILet8OwTL1A7+SYkltxkqcjnExS3dwTQekhgwzW3g=; fh=+IEfvAe+9BRgPHWhQEl2uIBTtAiiGDh1ExRZeB5JJoc=; b=brVoQytqfBpJ1RKmSBD2RYDa646jXvU8koqPR420eUV+X1zr/TFNlQiMj/5Gs5Hep+ GuQl74unmJM7utgt5cp9KarY9WLTtSJ+SNtIvNPYH8adb0eVUF15G4AzoUKjeX86e+ws B3bP+/JXAgzKhippcDGmVHoIkaFB9EFftWU9Y7LKoboAjY5uJ7LjHCO8yCRyIPEEsRtT +K6O8ni5gHq5Hdi0Cu8oS+vhpmUOOIdWvcnmgj5lUQHC55UqeSo5c9A40s6ENxm/8HzZ AOe2JFHrGeBI2GUYxTUV1m+OEkVyr7bJeCu12qdNnb3kVtzoXsmfuEMq4su6UzpPZ01p XZVQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=ih1LOBh0; arc=pass (i=1); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id bs20-20020a05620a471400b0077eff4d54b3si847513qkb.261.2023.12.06.13.54.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 13:54:45 -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=@gmx.de header.s=s31663417 header.b=ih1LOBh0; arc=pass (i=1); 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 69C733858023 for ; Wed, 6 Dec 2023 20:32:42 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784571165010061578 X-GMAIL-MSGID: 1784571165010061578 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