[Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
Hi all, this patch should finally fix up the last wrinkles of PR 45521, which deals with disambiguating specific procedures in a generic interface via the pointer/allocatable attributes of the arguments (legal in F08). For 'ordinary' generic interfaces this already works (cf. 'generic_correspondence'), but not for operator interfaces, which are treated a bit differently (see 'gfc_compare_interfaces'). The patch basically copies over the usage of 'compare_ptr_alloc' from 'generic_correspondence' to the relevant part of 'gfc_compare_interfaces'. Regtests cleanly on x86_64-linux-gnu. Ok for trunk? Cheers, Janus 2018-08-04 Janus Weil PR fortran/45521 * interface.c (gfc_compare_interfaces): Apply additional distinguishability criteria of F08 to operator interfaces. 2018-08-04 Janus Weil PR fortran/45521 * gfortran.dg/interface_assignment_6.f90: New test case. Index: gcc/fortran/interface.c === --- gcc/fortran/interface.c (revision 263178) +++ gcc/fortran/interface.c (working copy) @@ -1776,7 +1776,7 @@ } else { - /* Only check type and rank. */ + /* Operators: Only check type and rank of arguments. */ if (!compare_type (f2->sym, f1->sym)) { if (errmsg != NULL) @@ -1794,6 +1794,15 @@ symbol_rank (f2->sym)); return false; } + if ((gfc_option.allow_std & GFC_STD_F2008) + && (compare_ptr_alloc(f1->sym, f2->sym) + || compare_ptr_alloc(f2->sym, f1->sym))) + { + if (errmsg != NULL) + snprintf (errmsg, err_len, "Mismatching POINTER/ALLOCATABLE " + "attribute in argument '%s' ", f1->sym->name); + return false; + } } } ! { dg-do compile } ! ! PR 45521: [F08] GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE ! ! Contributed by Janus Weil module inteface_assignment_6 type :: t end type ! this was rejected as ambiguous, but is valid in F08 interface assignment(=) procedure testAlloc procedure testPtr end interface contains subroutine testAlloc(obj, val) type(t), allocatable, intent(out) :: obj integer, intent(in) :: val end subroutine subroutine testPtr(obj, val) type(t), pointer, intent(out) :: obj integer, intent(in) :: val end subroutine end
Re: [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
2018-06-11 19:49 GMT+02:00 Steve Kargl : > On Mon, Jun 11, 2018 at 05:05:17PM +0200, Janus Weil wrote: >> >> the attached patch fixes two remaining problems with the resolution of >> generic functions with POINTER and ALLOCATABLE arguments in F08 >> (coments 16 & 17 in the PR): >> * it deals with an INTENT(IN) condition that was added in an IR >> * it deals with polymorphic arguments, which were mistreated previously. >> >> The patch regtests cleanly on x86_64-linux-gnu. Ok for trunk? >> > > Yes. Thanks for the patch. Thanks for the review, Steve. Committed as r261448. Cheers, Janus
Re: [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
On Mon, Jun 11, 2018 at 05:05:17PM +0200, Janus Weil wrote: > > the attached patch fixes two remaining problems with the resolution of > generic functions with POINTER and ALLOCATABLE arguments in F08 > (coments 16 & 17 in the PR): > * it deals with an INTENT(IN) condition that was added in an IR > * it deals with polymorphic arguments, which were mistreated previously. > > The patch regtests cleanly on x86_64-linux-gnu. Ok for trunk? > Yes. Thanks for the patch. -- Steve
[Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
Hi all, the attached patch fixes two remaining problems with the resolution of generic functions with POINTER and ALLOCATABLE arguments in F08 (coments 16 & 17 in the PR): * it deals with an INTENT(IN) condition that was added in an IR * it deals with polymorphic arguments, which were mistreated previously. The patch regtests cleanly on x86_64-linux-gnu. Ok for trunk? Cheers, Janus 2018-06-11 Janus Weil PR fortran/45521 * interface.c (compare_ptr_alloc): New function. (compare_ptr_alloc): Call it. 2018-06-11 Janus Weil PR fortran/45521 * gfortran.dg/generic_32.f90: New test. * gfortran.dg/generic_33.f90: New test. Index: gcc/fortran/interface.c === --- gcc/fortran/interface.c (revision 261393) +++ gcc/fortran/interface.c (working copy) @@ -1190,6 +1190,24 @@ } +/* Returns true if two dummy arguments are distinguishable due to their POINTER + and ALLOCATABLE attributes according to F2018 section 15.4.3.4.5 (3). + The function is asymmetric wrt to the arguments s1 and s2 and should always + be called twice (with flipped arguments in the second call). */ + +static bool +compare_ptr_alloc(gfc_symbol *s1, gfc_symbol *s2) +{ + /* Is s1 allocatable? */ + const bool a1 = s1->ts.type == BT_CLASS ? + CLASS_DATA(s1)->attr.allocatable : s1->attr.allocatable; + /* Is s2 a pointer? */ + const bool p2 = s2->ts.type == BT_CLASS ? + CLASS_DATA(s2)->attr.class_pointer : s2->attr.pointer; + return a1 && p2 && (s2->attr.intent != INTENT_IN); +} + + /* Perform the correspondence test in rule (3) of F08:C1215. Returns zero if no argument is found that satisfies this rule, nonzero otherwise. 'p1' and 'p2' are the PASS arguments of both procedures @@ -1233,8 +1251,8 @@ if (f2 != NULL && (compare_type_rank (f1->sym, f2->sym) || compare_type_rank (f2->sym, f1->sym)) && !((gfc_option.allow_std & GFC_STD_F2008) - && ((f1->sym->attr.allocatable && f2->sym->attr.pointer) - || (f2->sym->attr.allocatable && f1->sym->attr.pointer + && (compare_ptr_alloc(f1->sym, f2->sym) + || compare_ptr_alloc(f2->sym, f1->sym goto next; /* Now search for a disambiguating keyword argument starting at @@ -1247,8 +1265,8 @@ sym = find_keyword_arg (g->sym->name, f2_save); if (sym == NULL || !compare_type_rank (g->sym, sym) || ((gfc_option.allow_std & GFC_STD_F2008) - && ((sym->attr.allocatable && g->sym->attr.pointer) - || (sym->attr.pointer && g->sym->attr.allocatable + && (compare_ptr_alloc(sym, g->sym) + || compare_ptr_alloc(g->sym, sym return true; } ! { dg-do compile } ! ! PR 45521: [F08] GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE ! ! Contributed by Janus Weil INTERFACE gen SUBROUTINE suba(a) ! { dg-error "Ambiguous interfaces" } REAL,ALLOCATABLE :: a(:) END SUBROUTINE SUBROUTINE subp(p) ! { dg-error "Ambiguous interfaces" } REAL,POINTER,INTENT(IN) :: p(:) END SUBROUTINE END INTERFACE end ! { dg-do compile } ! ! PR 45521: [F08] GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE ! ! Contributed by Janus Weil type :: t end type interface test procedure testAlloc procedure testPtr end interface contains logical function testAlloc(obj) class(t), allocatable :: obj testAlloc = .true. end function logical function testPtr(obj) class(t), pointer :: obj testPtr = .false. end function end
Re: [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
Hi, the attached patch implements an F08 feature, which allows to distinguish two specific procedures in a generic interface, based on the POINTER and ALLOCATABLE attribute of their arguments. In addition to this, the patch fixes a bug in rejecting data actual arguments passed to procedure formal arguments. The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk? Looks good, yes. Thanks. thanks, Mikael. Committed as r192157. Cheers, Janus
[Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
Hi all, the attached patch implements an F08 feature, which allows to distinguish two specific procedures in a generic interface, based on the POINTER and ALLOCATABLE attribute of their arguments. In addition to this, the patch fixes a bug in rejecting data actual arguments passed to procedure formal arguments. The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk? Cheers, Janus 2012-10-03 Janus Weil ja...@gcc.gnu.org PR fortran/45521 * interface.c (generic_correspondence): Implement additional distinguishability criteria of F08. (compare_actual_formal): Reject data object as actual argument for procedure formal argument. 2012-10-03 Janus Weil ja...@gcc.gnu.org PR fortran/45521 * gfortran.dg/generic_25.f90: New. * gfortran.dg/generic_26.f90: New. * gfortran.dg/generic_27.f90: New. pr45521_v2.diff Description: Binary data generic_25.f90 Description: Binary data generic_26.f90 Description: Binary data generic_27.f90 Description: Binary data