From patchwork Tue Mar 14 19:38:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 69823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1948938wrd; Tue, 14 Mar 2023 12:40:02 -0700 (PDT) X-Google-Smtp-Source: AK7set8rOUwuSL3GHpDYmCClDR9J776mw/hCX29+r3C3E003EDFGg0SBgLbRxHY7vnSiQU0Icz2G X-Received: by 2002:aa7:c052:0:b0:4fd:29e6:701b with SMTP id k18-20020aa7c052000000b004fd29e6701bmr221867edo.38.1678822802174; Tue, 14 Mar 2023 12:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678822802; cv=none; d=google.com; s=arc-20160816; b=SkOMvdjyQqWbpvgTG4bSUmG7+PcizHylN1agZbSQIgvahyV16Fb0hQ7XBr7h0IqsLs 9IlGbi+mpR7bro04kMsJjPHFKoVmgIrr/xU4fp4NclTpNQT60EFgTFxCn/bJvJ6fuL6Q X4bsOxZrtT9WO8tL4YJB8pWPtj5oW4zF528tvawb9HPrQkdPQP/i8HmluSbzCUGeYt4j +J03annAw9qXc3iSmZnGuyFJLngxJpab5pRDcQQIvLImeK0mpn2rfqTTlsw0O/j+3DVe lIKksMQX9JPvQqVPGRqkAjK/8ewYMjZ2sDhGufmPpxghuIdEpyQRLlEW+3xSDi3kFfpD lBfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:cc:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=wwv1myNY5H5mksx42Y5tcs93zQOAqssKy/W8IBYGplA=; b=eAjyX9oPfLiJBe/JE3g0KJmCTxVD/b7J/Dkg4dUpcU41BJFYx3S4/HJdy558rX7uMR swZsQ813yPSArMf4wdml2Zd0Vx+3S0K2LAQ0p5fqOvy/tTH16Lx1cjc3dfFwsADD1AVH O/MlZjf2RWbysOax1aPiSN9zMt7LF6vadlcgpCtpN3KKZw2N+wFAbJZwZ1i7fld8YRYA +LGe/aYGjWZu+bje/MNyXF+KOVNC/Z3Uq8C4QXGYCeN/UVlCaRvXa5n+HcDoptZteqGV djkvwSAo6gr/myRAe4PqMpZL3fhtiBwfNQWyiU/NZSgVik0MEkxCaZRdTxwLtqGuLJxZ CEsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eztGi9HN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id t1-20020a05640203c100b004fc687ac2a7si3150232edw.360.2023.03.14.12.40.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 12:40:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eztGi9HN; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA8053858005 for ; Tue, 14 Mar 2023 19:39:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA8053858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678822781; bh=wwv1myNY5H5mksx42Y5tcs93zQOAqssKy/W8IBYGplA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=eztGi9HN4rgrHuzOSaLPQU4+Il4/9cWXhEhkbTb9Bj7esb47nG4xqc1BXucMSvFt/ SkwuaJAiBuVK3mMxhnUN3a4BsJweOz5SJM0REsysT+W2QcutiRDXCzdicFj61HNdEg 9RENyJKbvJiiPHJVnPaicUxjq3gB/Bd5OQwdQY4o= 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.22]) by sourceware.org (Postfix) with ESMTPS id 4255F385841A; Tue, 14 Mar 2023 19:38:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4255F385841A X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.80.102] ([93.207.80.102]) by web-mail.gmx.net (3c-app-gmx-bap12.server.lan [172.19.172.82]) (via HTTP); Tue, 14 Mar 2023 20:38:47 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Cc: tobias@codesourcery.com Subject: [PATCH] Fortran: rank checking with explicit-/assumed-size arrays and CLASS [PR58331] Date: Tue, 14 Mar 2023 20:38:47 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:t7gqnGbRUKvoKm98e+r7Rclo8y+f7oVN7VcNr41vmb6Ao986cZJPDp0+QD1sNO2FejrMe zZyQm1Y518XgSTdnG+AW8jo9W61QyvHhf9GbsrrPYE9WXZjTpjxGAaXtX9u0xB8utEVhs3dDa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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 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760373298737048435?= X-GMAIL-MSGID: =?utf-8?q?1760373298737048435?= Dear all, the attached patch, which is based on a draft by Tobias, fixes an old rejects-valid issue with rank checking for CLASS arrays by using the proper array spec of CLASS variables. The testcase covers only non-coarray cases, as playing with coarray variants hit pre-exisiting issues in gfortran that are very likely unrelated to the interface checks. I consider this rather as post 13-release stuff. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From 4453686ae4e70c14a0898c6687db912fa84ece9f Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 14 Mar 2023 20:23:06 +0100 Subject: [PATCH] Fortran: rank checking with explicit-/assumed-size arrays and CLASS [PR58331] gcc/fortran/ChangeLog: PR fortran/58331 * interface.cc (compare_parameter): Adjust check of array dummy arguments to handle the case of CLASS variables. gcc/testsuite/ChangeLog: PR fortran/58331 * gfortran.dg/class_dummy_10.f90: New test. Co-authored-by: Tobias Burnus --- gcc/fortran/interface.cc | 27 +++++++--- gcc/testsuite/gfortran.dg/class_dummy_10.f90 | 56 ++++++++++++++++++++ 2 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/class_dummy_10.f90 diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index dafe41753b7..1d0f8bb5915 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -2349,6 +2349,7 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual, char err[200]; gfc_component *ppc; bool codimension = false; + gfc_array_spec *formal_as; /* If the formal arg has type BT_VOID, it's to one of the iso_c_binding procs c_f_pointer or c_f_procpointer, and we need to accept most @@ -2540,6 +2541,9 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual, return false; } + formal_as = formal->ts.type == BT_CLASS ? CLASS_DATA (formal)->as + : formal->as; + if (codimension && formal->attr.allocatable) { gfc_ref *last = NULL; @@ -2650,10 +2654,10 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual, if (symbol_rank (formal) == actual->rank || symbol_rank (formal) == -1) return true; - rank_check = where != NULL && !is_elemental && formal->as - && (formal->as->type == AS_ASSUMED_SHAPE - || formal->as->type == AS_DEFERRED) - && actual->expr_type != EXPR_NULL; + rank_check = where != NULL && !is_elemental && formal_as + && (formal_as->type == AS_ASSUMED_SHAPE + || formal_as->type == AS_DEFERRED) + && actual->expr_type != EXPR_NULL; /* Skip rank checks for NO_ARG_CHECK. */ if (formal->attr.ext_attr & (1 << EXT_ATTR_NO_ARG_CHECK)) @@ -2662,14 +2666,20 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual, /* Scalar & coindexed, see: F2008, Section 12.5.2.4. */ if (rank_check || ranks_must_agree || (formal->attr.pointer && actual->expr_type != EXPR_NULL) - || (actual->rank != 0 && !(is_elemental || formal->attr.dimension)) + || (actual->rank != 0 + && !(is_elemental || formal->attr.dimension + || (formal->ts.type == BT_CLASS + && CLASS_DATA (formal)->attr.dimension))) || (actual->rank == 0 && ((formal->ts.type == BT_CLASS && CLASS_DATA (formal)->as->type == AS_ASSUMED_SHAPE) || (formal->ts.type != BT_CLASS && formal->as->type == AS_ASSUMED_SHAPE)) && actual->expr_type != EXPR_NULL) - || (actual->rank == 0 && formal->attr.dimension + || (actual->rank == 0 + && (formal->attr.dimension + || (formal->ts.type == BT_CLASS + && CLASS_DATA (formal)->attr.dimension)) && gfc_is_coindexed (actual)) /* Assumed-rank actual argument; F2018 C838. */ || actual->rank == -1) @@ -2690,7 +2700,10 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual, } return false; } - else if (actual->rank != 0 && (is_elemental || formal->attr.dimension)) + else if (actual->rank != 0 + && (is_elemental || formal->attr.dimension + || (formal->ts.type == BT_CLASS + && CLASS_DATA (formal)->attr.dimension))) return true; /* At this point, we are considering a scalar passed to an array. This diff --git a/gcc/testsuite/gfortran.dg/class_dummy_10.f90 b/gcc/testsuite/gfortran.dg/class_dummy_10.f90 new file mode 100644 index 00000000000..cee5d4d82b2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/class_dummy_10.f90 @@ -0,0 +1,56 @@ +! { dg-do compile } +! PR fortran/58331 - rank checking for CLASS dummy arguments + +module mymod + implicit none +contains + subroutine mysub(a, n) + integer, intent(in) :: n + class(*), intent(in) :: a(n) + + select type(a) + type is(integer) + print *,'a is integer' + print *, "n=", n, ' a=', a + class default + print *,'a is unsupported type' + stop 1 + end select + end + + ! Assumed rank + subroutine sub_ar (a) + class(*), intent(in) :: a(..) + print *, rank (a), size (a), ":", shape (a) + end + + ! Assumed shape + subroutine sub_as1 (a) + class(*), intent(in) :: a(:) + print *, rank (a), size (a), ":", shape (a) + end + subroutine sub_as2 (b) + class(*), intent(in) :: b(:,:) + print *, rank (b), size (b), ":", shape (b) + end +end + +program p + use mymod + implicit none + integer :: a(3) = [11, 12, 13] + integer :: b(2,2) = reshape([21, 22, 23, 24], [2,2]) + integer :: c = 1 + + call mysub(a,3) + call mysub(b,4) + call sub_ar(a) + call sub_ar(b) + call sub_ar(c) + call sub_as1(a) + call sub_as2(b) + ! + call mysub(c,1) ! { dg-error "rank-1 and scalar" } + call sub_as1(b) ! { dg-error "rank-1 and rank-2" } + call sub_as2(a) ! { dg-error "rank-2 and rank-1" } +end -- 2.35.3