From patchwork Fri Dec 8 10:28:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 175789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp5390431vqy; Fri, 8 Dec 2023 03:32:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/R9k/UmBE+ujnvNw8Tu8JKaJOToj5Uio8m58ZLXhBaRDNRXdyDuo+QhEnPuW8L9gxUaO6 X-Received: by 2002:a05:6808:2014:b0:3b9:e48f:d653 with SMTP id q20-20020a056808201400b003b9e48fd653mr1998399oiw.66.1702035126200; Fri, 08 Dec 2023 03:32:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702035126; cv=pass; d=google.com; s=arc-20160816; b=vTY97rWYeZdlcpNs/fCULHTdwIoCmDGp7hOIpuVN9qJviVJsM4QmuajAthpssTeM5F qYvh+ReoTkQ3Vf7JH/i/M1pEzE+mllh/QYqpwd7KqxLUImRsW76Te/dlCWwhQz6cE14o 1e2aJ6nmbJx04HS9MOLOdj8geSVi8BekJ3ZJwsKECsoOKrEMj/qUe51Cnh0K9ENyZJdH kl/YOHaXoAmxonF+TxlTi6lPG87iKoH2ILPikn+EfSiCEuovHfFGo6JKvxA5028JoJPK PUgzLgtfYZeF/hi1rtc6PMG02LREb9tLZ/dwylbvVp1jeInmLKJ9+sCXHKOrc6pbjVXv /yqg== 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=z0RECKVceZWpHv0/6/eCM/3wQ8YIaw5XLchjbATY+hY=; fh=+IEfvAe+9BRgPHWhQEl2uIBTtAiiGDh1ExRZeB5JJoc=; b=u5okvATEXIdEucNCFjBy5owD1yQA10+AZqrailxQ8UCL9czj4oZy7pV8ruFD+1zPbe Aws6MTs9s7q/EZjv3TxgWIs72Synk8bJmdbbi81ppleshCtJnYqQf62q5CyKUbH/B43a IbWyi3flMC+p+Zh4wcsxKJeaIzwGxtFbnEj2ZymTNhSTVPm7KWZwRaS2wgqt3byOqoAb GsrQFEn7EH0QLjFZ7NKPwsw35JoQhXqhTo2nH8WIqVW0r02bCkXrCFybJmmTHrnKA6yU x3ctTY/uQlxRUzAdGR3+wQMBmMFeIVFohSr0ip6xJHpsMfwThs93/sruqfL7T321uFmF Nf3g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.de header.s=s31663417 header.b=L9Nze7iL; 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 a22-20020ac84d96000000b0042543b4e1cdsi1847995qtw.788.2023.12.08.03.32.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 03:32:06 -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=L9Nze7iL; 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 97C5E3857BB2 for ; Fri, 8 Dec 2023 10:28:31 +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.19]) by sourceware.org (Postfix) with ESMTPS id 313663858CDB; Fri, 8 Dec 2023 10:28:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 313663858CDB 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 313663858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=212.227.15.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702031288; cv=none; b=l17kIJKZD9rR9JIPsItnPydV4xKETf9zPpFVBjqvjbG30z4jbEny6U/v3Rn+w1trz3Kqc0U/llc9VLafmMYRG0siiXUzmoBxUrjZaw1uj7Ti9JoYr0WTSLXlRXQz0aMp/csqmBsd+fXnW+1xWQgaMdDVAYGW7S2kcWhEDhNnzTk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702031288; c=relaxed/simple; bh=YsuOmqGW07qLNVp+W/k+0elvo9m2GL88X7a3IRZC/bs=; h=DKIM-Signature:MIME-Version:Message-ID:From:To:Subject:Date; b=xtlnv1ddxnEWnn0nXY0xQ9PRvMdeSk3OHsGome27P8vgUS6cyBK4V80ERvudOV0/qdZmcaPHhGpThwTZyXCHhFroCTBkn7yrjZTA3k92M7uPzAuI4GfVdfLD65IALzdIXdoEtMe9N+kfPYOfspDyeZ2eltonPqApbWnLW7HC/3E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1702031284; x=1702636084; i=anlauf@gmx.de; bh=YsuOmqGW07qLNVp+W/k+0elvo9m2GL88X7a3IRZC/bs=; h=X-UI-Sender-Class:From:To:Subject:Date; b=L9Nze7iL5Cf6yaYwdsWrMi1rYgf0BV6JsY6vA/3jN0uiLKuJbwlPhliQv/0QDODZ AvuWc6DezTNFnUAIl5D9cieY7N9NSWCqn/Zdac8b8XYqLq94G2Jp53jFGs4RTKfF/ BhnSKIpE/e0pwsJKSgYJYz4i/1y/afyQKnJusucsOw7chaes9Eg7/p+gsfiu9U0LC 2TbGON6EWBg22PMGsCpeWDVVT4931JLqJoakchXFBoyjIivYc+3J7imZL8ut8FEnR g+yAgL3j4xgF/RslIUra7KZdebolgvLJd+2jZSMk2QlHKZ8k15Wl3anZnkvEEpWXI RNvM7pFfFM77nThCsg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.2.149] ([79.251.2.149]) by web-mail.gmx.net (3c-app-gmx-bs48.server.lan [172.19.170.101]) (via HTTP); Fri, 8 Dec 2023 11:28:04 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: allow NULL() for POINTER, OPTIONAL, CONTIGUOUS dummy [PR111503] Date: Fri, 8 Dec 2023 11:28:04 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:J+0blUbSI8WzEJzTz7dKhw0YqNC57MDPSX1A+Y8QPQkxjDQZrkfc9/XlpVkjPCfibo1Jf +J0U8fRIFu1WMjZV1svz4/FD752IFsnHLaMaaocEvQ/YVjJCSFC8NF2JOg0MQgWWJ7qgBs2czHc/ E/ixzKsQ/DOAXgFL/KVAvQqb9BkpHAD06TqE31EiRmYAWPj95dyzS3HrxlPZWwcOMkI5FqcpO5/5 o3YR1jO+8TeS5yJIOIzswk7xr4zynQXLPIiIbwV+R4NTjyG1fPnVpFrkaxuS3XcPiNURorgxjlTX ic= UI-OutboundReport: notjunk:1;M01:P0:ohacS08mp3g=;941Q5ryZZkCC1UtZe2zEiZHUjkK SMKW4olexZpe2UZYuswlmhwjuFeRBGBHWE7UvYxnfNaJKlQ3feuDRuBDiG58g+LeVjuFApfL3 fDabakSkXzKIQaP5vI/BBvu4oXI32wlnPgpdOjZAnIyd/idfVB3/RgWBE2bOmDVMvtVIZP7A0 0Gx+Pbda8RZPJiDOuV+Brmz8s6zcndsCbKfiaty+cWCnMnjZByWKmpCjtut2n7waorSqvdhnj LNCntJK7Z7zd9nhmg4LdUdbO91tp4Am9Wg0e++lGqok5Ow8qAa0DQwpd58k24NsXkMb/w5SUP kyzg8Qd7SfZZSVD3peDuMX+cFFibG9CahVLEmwdEoHB+hrM0Mqp7pT9aWLdtqZunxlpPcAuxC JwdfJLYH9u5tCDJfYKZGEJzMcHp8UxxQUNbIYyk0/S1/TEZQDdc4Lmkn8NO3teVvXi/OBL4wQ 3CkxRc73WrckJQNZfjKflXkBmWB4x0mGZ6fCg/BxFP6adSICD0FWpaG8wAnRCJmiUBoDuH/nZ vI3Xbd5xx19fdVuYzc229rfLmV5vGy3bSZ7HE3Y4U60j4kwl88DLGhIVsQf/oC/zovip4cHew efgLRdjz6LRQvvGCyGZ7cPXhy/fdy9vebW6tq5NzMBCmhzZ3YfVdmySuxw0xQ+R8pa3B+MaEA IBAI+08tegQKXFm4t6cX5mp9b/p7/FyQKAtF1gT3YL1wKhbbzAA32PBumGUW65diND3SPjSij orSuV/ZW08EmWPqKIvUh/PfOncx5+KAlh00hPaHCxlXfZ0eQQGvcNACDwC/yPxoJfIe49lHe0 cQ+ibwENK6RYvVVUR2ZHktGw== X-Spam-Status: No, score=-10.6 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_H3, 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: 1784713184421645076 X-GMAIL-MSGID: 1784713184421645076 Dear all, here's another fix for the CONTIGUOUS attribute: NULL() should derive its characteristics from its MOLD argument; otherwise it is "determined by the entity with which the reference is associated". (F2018:16.9.144). The testcase is cross-checked with Intel. NAG rejects cases where MOLD is a pointer. I think it is wrong here. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From c73b248ec16388ed1ce109fce8a468a87e367085 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Fri, 8 Dec 2023 11:11:08 +0100 Subject: [PATCH] Fortran: allow NULL() for POINTER, OPTIONAL, CONTIGUOUS dummy [PR111503] gcc/fortran/ChangeLog: PR fortran/111503 * expr.cc (gfc_is_simply_contiguous): Determine characteristics of NULL() from MOLD argument if present, otherwise treat as present. * primary.cc (gfc_variable_attr): Derive attributes of NULL(MOLD) from MOLD. gcc/testsuite/ChangeLog: PR fortran/111503 * gfortran.dg/contiguous_14.f90: New test. --- gcc/fortran/expr.cc | 14 ++++++++ gcc/fortran/primary.cc | 4 ++- gcc/testsuite/gfortran.dg/contiguous_14.f90 | 39 +++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/contiguous_14.f90 diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index c668baeef8c..709f3c3cbef 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -5958,6 +5958,20 @@ gfc_is_simply_contiguous (gfc_expr *expr, bool strict, bool permit_element) if (expr->expr_type == EXPR_ARRAY) return true; + if (expr->expr_type == EXPR_NULL) + { + /* F2018:16.9.144 NULL ([MOLD]): + "If MOLD is present, the characteristics are the same as MOLD." + "If MOLD is absent, the characteristics of the result are + determined by the entity with which the reference is associated." + F2018:15.3.2.2 characteristics attributes include CONTIGUOUS. */ + if (expr->ts.type == BT_UNKNOWN) + return true; + else + return (gfc_variable_attr (expr, NULL).contiguous + || gfc_variable_attr (expr, NULL).allocatable); + } + if (expr->expr_type == EXPR_FUNCTION) { if (expr->value.function.isym) diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index 7278932b634..f8a1c09d190 100644 --- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -2627,7 +2627,9 @@ gfc_variable_attr (gfc_expr *expr, gfc_typespec *ts) gfc_component *comp; bool has_inquiry_part; - if (expr->expr_type != EXPR_VARIABLE && expr->expr_type != EXPR_FUNCTION) + if (expr->expr_type != EXPR_VARIABLE + && expr->expr_type != EXPR_FUNCTION + && !(expr->expr_type == EXPR_NULL && expr->ts.type != BT_UNKNOWN)) gfc_internal_error ("gfc_variable_attr(): Expression isn't a variable"); sym = expr->symtree->n.sym; diff --git a/gcc/testsuite/gfortran.dg/contiguous_14.f90 b/gcc/testsuite/gfortran.dg/contiguous_14.f90 new file mode 100644 index 00000000000..21e42311e9c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/contiguous_14.f90 @@ -0,0 +1,39 @@ +! { dg-do compile } +! PR fortran/111503 - passing NULL() to POINTER, OPTIONAL, CONTIGUOUS dummy + +program test + implicit none + integer, pointer, contiguous :: p(:) => null() + integer, allocatable, target :: a(:) + type t + integer, pointer, contiguous :: p(:) => null() + integer, allocatable :: a(:) + end type t + type(t), target :: z + class(t), allocatable, target :: c + print *, is_contiguous (p) + allocate (t :: c) + call one (p) + call one () + call one (null ()) + call one (null (p)) + call one (a) + call one (null (a)) + call one (z% p) + call one (z% a) + call one (null (z% p)) + call one (null (z% a)) + call one (c% p) + call one (c% a) + call one (null (c% p)) + call one (null (c% a)) +contains + subroutine one (x) + integer, pointer, optional, contiguous, intent(in) :: x(:) + print *, present (x) + if (present (x)) then + print *, "->", associated (x) + if (associated (x)) stop 99 + end if + end subroutine one +end -- 2.35.3