From patchwork Mon Apr 10 20:49:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 81634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2144247vqo; Mon, 10 Apr 2023 13:53:21 -0700 (PDT) X-Google-Smtp-Source: AKy350YwDKoph4FbW1cWhL48lhXBK3dMxgRvjFblfnPfsNfBYoTfokraIpFEHvD5sJLH9a4IEN96 X-Received: by 2002:a17:906:2981:b0:94b:ffe9:37fd with SMTP id x1-20020a170906298100b0094bffe937fdmr2184187eje.5.1681160001410; Mon, 10 Apr 2023 13:53:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681160001; cv=none; d=google.com; s=arc-20160816; b=0lahNnujS/aXULdpNvJYAQPnURX3WlHS79Dj30wG8wWWzVIHQ8l+749ANKAcnWQ9z7 892sTP1XP/SIlE5q+FvrJug1OW3N04pm0DqRiCZHp9PV0jz6z/F9AjYQWyyoaCOEWhQJ hw/f86Cslajagx4v+fAz0+Je78DdcDod26qnT0BF+CGnlvytc5G+opC3ly/amcyAhTpV XEFVB4Hv1MvREIMueJQbJe9IuxednqSPpECsi26Tbb39glQIICxkRVc089+LwSS6IGBU e6eGNsHHPG18BVOyfvD90Kzyg0vy6n36AC7KLqBVe2q3xxNKLc12faicfboqsfX3jJDB b+kw== 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:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=XvCSQP4mPMDxLBVGt2u6aMjpaIO7V7SRJYv8RhJMjUo=; b=CnrU51wI24VM87VoUeYiZkJmbOnqJGc6aA8k8Wbrcf42BNyk10V/SqM0mFmfL088IV uKeA5oOK9KXAcPC14kw7COpQXmFRJ8tOba92VcqeVQKkpvFiPYAik40AhWEa684X7B5S Bl5IzzONi4Jzo2Ky58WuvhVnskqFhm+3FXwkfJ35hftsAFsWZoPWvf4xYG0Mr3fnjwNk XSM2Iom7WO+U185rDUJDb4NJRwIqwfzWTvUMA+P2+P4/SX+qytjvzw4UvhU+26yZlB+7 hDySl6LhREZagJQjqtH/SzdguBQgpAhWBqnIs8iS0ohZ+732qrHFmALjMjCja1B01jy5 RZLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uBxp5uDv; 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=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id wt2-20020a170906ee8200b0094a88875e8fsi3738087ejb.1013.2023.04.10.13.53.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Apr 2023 13:53:21 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=uBxp5uDv; 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=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EEBA23856247 for ; Mon, 10 Apr 2023 20:51:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEBA23856247 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681159886; bh=XvCSQP4mPMDxLBVGt2u6aMjpaIO7V7SRJYv8RhJMjUo=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uBxp5uDvZerdGCG5oLIfiU1rcJ76JYMX/ECvnHMEHT90Lf1ouZeII0ABXBZ1AbQCL 3yMQZKGa3b8q7x5DOz5podQ6goc396xygq313B57zLWki8e8gsYTDIFO/pq1TYHxhn XdS5Ru0lN1CC4LEuVcXLEzsHBwIGRNTZTtCsLjt8= 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.15]) by sourceware.org (Postfix) with ESMTPS id E70123854166; Mon, 10 Apr 2023 20:49:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E70123854166 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.15.178] ([79.251.15.178]) by web-mail.gmx.net (3c-app-gmx-bs33.server.lan [172.19.170.85]) (via HTTP); Mon, 10 Apr 2023 22:49:46 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: resolve correct generic with TYPE(C_PTR) arguments [PR61615] Date: Mon, 10 Apr 2023 22:49:46 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:Cn7WTfZuyrLWNiMAYbuYHi/9sDGaEr6otfxOWFXvQgpYCDdOv6plMn80poMKyM79fjNIG Ew9WGXn9io1EKITOEDieqV04UoQQQzFK7IuBIa74aW8wW2UBq+piV75aEv4SW5f8j+kkfEh3IwhY uJqLeBdo/Wrlu1btdZuOT4W/N1NiHQawuXlnun3KUVkuxMYbUs8f6HFsgYNtb8IYSoXGcfDsME5g F17KJSYIMyD+VCHeSWOH6OO+tnV5yHIirnRPNZycqcsjWubfpVYnupyFkGzZvupSGnJUIwTHPmWc BA= UI-OutboundReport: notjunk:1;M01:P0:8ddz01Fmv1Y=;VfmSTcawai0N2/ykE6rBMWeMz3D 5HSenWEHxjMX/6CuaAF+wu2A3wu4veecWP6I3lB6+cFGVOM74kUPWOHzO1a5X6936+xxDdSkB sUIs5IBnO7XsCa8qiTbR8+UdhfUYPbOzVExvV1RnFeidx3z0NhNm2KW5yRBsYw/So86g5kE+f FOlB5H4713BqF9Pfrp2fIVi4BIW3oirnvuOfc++odSJABLBk3flBAn5Fj1GgSEr2V6Bt8rYqM P4S8+V/r+OU9/dvAdmyve3h+j8IsL0aBi1BrI0yQD07HAUKku6+Jw0XqPR0cBByICBEcqRIWM yTBKUqCJbfI/zN0o2/oCjHs62MO/dWppLilsaTkJ3RDyDaz2qr8RK0PhAtYncjo+30YOKPdDe l2PEHpcbRwP5pZqPiv2NDoh/OBjCMCiMjTnIF7GBzlBQOHnprIm/4AaGgha9eITmajdCCxaFQ k0RWfAE98s6G64ac80TyxjAumThKT28Y8nXWCVbvvCJNUG16Yl9NCeQ02IeH2B7F9J3edrKAz Z7bHL+MXPNzOYeNslS1nl9CdUdq7+QCRvVjZQJ3aVfUjC4o87sxEAar6307I5Ax7k3AsSGhBM lSqebPFoZBWrS/uGNVAF5bxr9dvwJBBK/V5n1zAsGDdARKA3YklVJyzTXAFwxGWiWRbdU/66B FugGXbClnCvI/0IvQFMHg8XXZImgdsvKTCKr3MdQDF5RwRqySa8J2/nsOKufql1xPBrhIFiTr hRKhFQv/LDEYrGPl/PKKaBpgNtj8aGzSMXBkNNrnl9bam2JrikInrOow5sfj0t3XNrb8o8RuA +9dR0XntjwfEbxi/m9Vcb4bg== X-Spam-Status: No, score=-12.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_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?1762824029335902927?= X-GMAIL-MSGID: =?utf-8?q?1762824029335902927?= Dear all, when comparing formal and actual arguments of a procedure, there was no check of rank for derived types from intrinsic module ISO_C_BINDING. This could lead to a wrong resolution of generic procedures with dummy argument of related types, see PR. This was likely an oversight. The attached fix is simple and regtests cleanly on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald From d41aa0f60b53799a5d28743f168fbf312461f51f Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Mon, 10 Apr 2023 22:39:52 +0200 Subject: [PATCH] Fortran: resolve correct generic with TYPE(C_PTR) arguments [PR61615] gcc/fortran/ChangeLog: PR fortran/61615 * interface.cc (compare_parameter): Enable rank check for arguments of derived type from the intrinsic module ISO_C_BINDING. gcc/testsuite/ChangeLog: PR fortran/61615 * gfortran.dg/interface_49.f90: New test. --- gcc/fortran/interface.cc | 14 ++++++- gcc/testsuite/gfortran.dg/interface_49.f90 | 43 ++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/interface_49.f90 diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index db79b104dc2..8682dc999be 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -2361,7 +2361,19 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual, && formal->ts.u.derived && formal->ts.u.derived->ts.is_iso_c && actual->ts.type == BT_DERIVED && actual->ts.u.derived && actual->ts.u.derived->ts.is_iso_c) - return true; + { + if (ranks_must_agree + && ((actual->rank == 0 && formal->attr.dimension) + || (actual->rank != 0 && !formal->attr.dimension))) + { + if (where) + argument_rank_mismatch (formal->name, &actual->where, + symbol_rank (formal), actual->rank, + NULL); + return false; + } + return true; + } if (formal->ts.type == BT_CLASS && actual->ts.type == BT_DERIVED) /* Make sure the vtab symbol is present when diff --git a/gcc/testsuite/gfortran.dg/interface_49.f90 b/gcc/testsuite/gfortran.dg/interface_49.f90 new file mode 100644 index 00000000000..67d3e3f871b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/interface_49.f90 @@ -0,0 +1,43 @@ +! { dg-do run } +! PR fortran/61615 - resolve correct generic with TYPE(C_PTR) arguments +! Contributed by Jacob Abel + +MODULE foo + USE iso_c_binding, only : c_ptr + IMPLICIT NONE + integer :: rank = -99 + INTERFACE bar + MODULE PROCEDURE bar_s + MODULE PROCEDURE bar_a1d + END INTERFACE bar +CONTAINS + SUBROUTINE bar_s(a) + TYPE(c_ptr) :: a + WRITE (0, *) 'in bar_s' + rank = 0 + END SUBROUTINE bar_s + + SUBROUTINE bar_a1d(a) + TYPE(c_ptr) :: a(:) + WRITE (0, *) 'in bar_a1d' + rank = 1 + END SUBROUTINE bar_a1d +END MODULE foo + +PROGRAM cptr_array_vs_scalar_arg + USE foo + USE iso_c_binding, only : c_ptr, c_loc + IMPLICIT NONE + INTEGER, TARGET :: i + TYPE(c_ptr) :: a, b(1) + a = C_LOC(i) + b(1) = C_LOC(i) + CALL bar(a) + if (rank /= 0) stop 1 + CALL bar(b) + if (rank /= 1) stop 2 + CALL bar((a)) + if (rank /= 0) stop 3 + CALL bar((b)) + if (rank /= 1) stop 4 +END PROGRAM cptr_array_vs_scalar_arg -- 2.35.3