public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-9467] Fortran: resolve correct generic with TYPE(C_PTR) arguments [PR61615, PR99982] Date: Sun, 23 Apr 2023 18:53:27 +0000 (GMT) [thread overview] Message-ID: <20230423185327.E0E823858412@sourceware.org> (raw) https://gcc.gnu.org/g:62a4f2fb356cab8cfebfeeac2895b657c32b8dd4 commit r12-9467-g62a4f2fb356cab8cfebfeeac2895b657c32b8dd4 Author: Harald Anlauf <anlauf@gmx.de> Date: Tue Apr 11 16:44:32 2023 +0200 Fortran: resolve correct generic with TYPE(C_PTR) arguments [PR61615,PR99982] gcc/fortran/ChangeLog: PR fortran/61615 PR fortran/99982 * interface.cc (compare_parameter): Enable type and rank checks for arguments of derived type from the intrinsic module ISO_C_BINDING. gcc/testsuite/ChangeLog: PR fortran/61615 PR fortran/99982 * gfortran.dg/interface_49.f90: New test. (cherry picked from commit c482995cc5bac4a2168ea0049041e712544e474b) Diff: --- gcc/fortran/interface.cc | 18 +++++- gcc/testsuite/gfortran.dg/interface_49.f90 | 95 ++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index fc23bb70193..874acb914f3 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -2354,7 +2354,23 @@ 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 (formal->ts.u.derived->intmod_sym_id + != actual->ts.u.derived->intmod_sym_id) + return false; + + if (ranks_must_agree + && symbol_rank (formal) != actual->rank + && symbol_rank (formal) != -1) + { + 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..aef5e0c6609 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/interface_49.f90 @@ -0,0 +1,95 @@ +! { dg-do run } +! PR fortran/61615 - resolve correct generic with TYPE(C_PTR) arguments +! PR fortran/99982 - dto. with C_PTR and C_FUNPTR +! Contributed by Jacob Abel and Scot Breitenfeld + +MODULE foo + USE iso_c_binding, only : c_ptr, c_funptr + IMPLICIT NONE + integer :: rank = -99 + character(8) :: ctyp = "" + INTERFACE bar + MODULE PROCEDURE bar_s + MODULE PROCEDURE bar_a1d + MODULE PROCEDURE bar_a2d + MODULE PROCEDURE bar_fp + MODULE PROCEDURE bar_fp1 + MODULE PROCEDURE bar_fpx + END INTERFACE bar +CONTAINS + SUBROUTINE bar_s(a) + TYPE(c_ptr) :: a + WRITE (0, *) 'in bar_s' + rank = 0 + ctyp = "c_ptr" + END SUBROUTINE bar_s + + SUBROUTINE bar_a1d(a) + TYPE(c_ptr) :: a(:) + WRITE (0, *) 'in bar_a1d' + rank = 1 + ctyp = "c_ptr" + END SUBROUTINE bar_a1d + + SUBROUTINE bar_a2d(a) + TYPE(c_ptr) :: a(:,:) + WRITE (0, *) 'in bar_a2d' + rank = 2 + ctyp = "c_ptr" + END SUBROUTINE bar_a2d + + SUBROUTINE bar_fp(a) + TYPE(c_funptr) :: a + WRITE (0, *) 'in bar_fp' + rank = 0 + ctyp = "c_funptr" + END SUBROUTINE bar_fp + + SUBROUTINE bar_fp1(a) + TYPE(c_funptr) :: a(:) + WRITE (0, *) 'in bar_fp1' + rank = 1 + ctyp = "c_funptr" + END SUBROUTINE bar_fp1 + + SUBROUTINE bar_fpx(a, b) + TYPE(c_funptr) :: a(..) + TYPE(c_ptr) :: b + WRITE (0, *) 'in bar_fpx' + rank = -1 + ctyp = "c_funptr" + END SUBROUTINE bar_fpx +END MODULE foo + +PROGRAM cptr_array_vs_scalar_arg + USE foo + USE iso_c_binding, only : c_ptr, c_loc, c_funptr + IMPLICIT NONE + INTEGER, TARGET :: i + TYPE(c_ptr) :: a, b(1), c(1,1) + type(c_funptr) :: fp, fp1(1), fp2(1,1) + a = C_LOC(i) + b(1) = C_LOC(i) + CALL bar(a) + if (rank /= 0 .or. ctyp /= "c_ptr") stop 1 + CALL bar(b) + if (rank /= 1 .or. ctyp /= "c_ptr") stop 2 + CALL bar(c) + if (rank /= 2 .or. ctyp /= "c_ptr") stop 3 + rank = -99 + ctyp = "" + CALL bar((a)) + if (rank /= 0 .or. ctyp /= "c_ptr") stop 4 + CALL bar((b)) + if (rank /= 1 .or. ctyp /= "c_ptr") stop 5 + rank = -99 + ctyp = "" + CALL bar(fp) + if (rank /= 0 .or. ctyp /= "c_funptr") stop 6 + CALL bar(fp1) + if (rank /= 1 .or. ctyp /= "c_funptr") stop 7 + rank = -99 + ctyp = "" + CALL bar(fp2, a) + if (rank /= -1 .or. ctyp /= "c_funptr") stop 8 +END PROGRAM cptr_array_vs_scalar_arg
reply other threads:[~2023-04-23 18:53 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230423185327.E0E823858412@sourceware.org \ --to=anlauf@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).