* [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
@ 2018-06-11 15:24 Janus Weil
2018-06-11 18:17 ` Steve Kargl
0 siblings, 1 reply; 9+ messages in thread
From: Janus Weil @ 2018-06-11 15:24 UTC (permalink / raw)
To: gfortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 699 bytes --]
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 <janus@gcc.gnu.org>
PR fortran/45521
* interface.c (compare_ptr_alloc): New function.
(compare_ptr_alloc): Call it.
2018-06-11 Janus Weil <janus@gcc.gnu.org>
PR fortran/45521
* gfortran.dg/generic_32.f90: New test.
* gfortran.dg/generic_33.f90: New test.
[-- Attachment #2: pr45521.diff --]
[-- Type: text/x-patch, Size: 2033 bytes --]
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;
}
[-- Attachment #3: generic_32.f90 --]
[-- Type: text/x-fortran, Size: 419 bytes --]
! { dg-do compile }
!
! PR 45521: [F08] GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
!
! Contributed by Janus Weil <janus@gcc.gnu.org>
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
[-- Attachment #4: generic_33.f90 --]
[-- Type: text/x-fortran, Size: 472 bytes --]
! { dg-do compile }
!
! PR 45521: [F08] GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
!
! Contributed by Janus Weil <janus@gcc.gnu.org>
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
2018-06-11 15:24 [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE Janus Weil
@ 2018-06-11 18:17 ` Steve Kargl
2018-06-11 21:15 ` Janus Weil
0 siblings, 1 reply; 9+ messages in thread
From: Steve Kargl @ 2018-06-11 18:17 UTC (permalink / raw)
To: Janus Weil; +Cc: gfortran, gcc-patches
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
2018-06-11 18:17 ` Steve Kargl
@ 2018-06-11 21:15 ` Janus Weil
0 siblings, 0 replies; 9+ messages in thread
From: Janus Weil @ 2018-06-11 21:15 UTC (permalink / raw)
To: Steve Kargl; +Cc: gfortran, gcc-patches
2018-06-11 19:49 GMT+02:00 Steve Kargl <sgk@troutmask.apl.washington.edu>:
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
2018-08-04 15:14 ` Jerry DeLisle
@ 2018-08-04 15:38 ` Janus Weil
0 siblings, 0 replies; 9+ messages in thread
From: Janus Weil @ 2018-08-04 15:38 UTC (permalink / raw)
To: Jerry DeLisle; +Cc: gfortran
2018-08-04 17:14 GMT+02:00 Jerry DeLisle <jvdelisle@charter.net>:
> On 08/04/2018 07:50 AM, Janus Weil wrote:
>>
>> 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?
>
>
>
> OK, and thanks for patch.
Thanks for the quick review, Jerry. Committed as r263308.
Cheers,
Janus
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
2018-08-04 14:50 Janus Weil
@ 2018-08-04 15:14 ` Jerry DeLisle
2018-08-04 15:38 ` Janus Weil
0 siblings, 1 reply; 9+ messages in thread
From: Jerry DeLisle @ 2018-08-04 15:14 UTC (permalink / raw)
To: fortran; +Cc: janus@gcc.gnu.org >> Janus Weil
On 08/04/2018 07:50 AM, Janus Weil wrote:
> 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?
OK, and thanks for patch.
Jerry
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
@ 2018-08-04 14:50 Janus Weil
2018-08-04 15:14 ` Jerry DeLisle
0 siblings, 1 reply; 9+ messages in thread
From: Janus Weil @ 2018-08-04 14:50 UTC (permalink / raw)
To: gfortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 941 bytes --]
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 <janus@gcc.gnu.org>
PR fortran/45521
* interface.c (gfc_compare_interfaces): Apply additional
distinguishability criteria of F08 to operator interfaces.
2018-08-04 Janus Weil <janus@gcc.gnu.org>
PR fortran/45521
* gfortran.dg/interface_assignment_6.f90: New test case.
[-- Attachment #2: pr45521_assign_op.diff --]
[-- Type: text/x-patch, Size: 833 bytes --]
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;
+ }
}
}
[-- Attachment #3: interface_assignment_6.f90 --]
[-- Type: text/x-fortran, Size: 610 bytes --]
! { dg-do compile }
!
! PR 45521: [F08] GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
!
! Contributed by Janus Weil <janus@gcc.gnu.org>
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
2012-10-06 10:23 ` Mikael Morin
@ 2012-10-06 12:22 ` Janus Weil
0 siblings, 0 replies; 9+ messages in thread
From: Janus Weil @ 2012-10-06 12:22 UTC (permalink / raw)
To: Mikael Morin; +Cc: gfortran, gcc-patches
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
2012-10-03 22:06 Janus Weil
@ 2012-10-06 10:23 ` Mikael Morin
2012-10-06 12:22 ` Janus Weil
0 siblings, 1 reply; 9+ messages in thread
From: Mikael Morin @ 2012-10-06 10:23 UTC (permalink / raw)
To: Janus Weil; +Cc: gfortran, gcc-patches
Hello,
Le 04/10/2012 00:06, Janus Weil a écrit :
> 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?
>
Looks good, yes. Thanks.
Mikael
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
@ 2012-10-03 22:06 Janus Weil
2012-10-06 10:23 ` Mikael Morin
0 siblings, 1 reply; 9+ messages in thread
From: Janus Weil @ 2012-10-03 22:06 UTC (permalink / raw)
To: gfortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 831 bytes --]
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 <janus@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 <janus@gcc.gnu.org>
PR fortran/45521
* gfortran.dg/generic_25.f90: New.
* gfortran.dg/generic_26.f90: New.
* gfortran.dg/generic_27.f90: New.
[-- Attachment #2: pr45521_v2.diff --]
[-- Type: application/octet-stream, Size: 3471 bytes --]
Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c (revision 192005)
+++ gcc/fortran/interface.c (working copy)
@@ -934,9 +934,9 @@ count_types_test (gfc_formal_arglist *f1, gfc_form
}
-/* Perform the correspondence test in rule 3 of section F03:16.2.3.
- Returns zero if no argument is found that satisfies rule 3, nonzero
- otherwise. 'p1' and 'p2' are the PASS arguments of both procedures
+/* 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
(if applicable).
This test is also not symmetric in f1 and f2 and must be called
@@ -944,13 +944,13 @@ count_types_test (gfc_formal_arglist *f1, gfc_form
argument list with keywords. For example:
INTERFACE FOO
- SUBROUTINE F1(A, B)
- INTEGER :: A ; REAL :: B
- END SUBROUTINE F1
+ SUBROUTINE F1(A, B)
+ INTEGER :: A ; REAL :: B
+ END SUBROUTINE F1
- SUBROUTINE F2(B, A)
- INTEGER :: A ; REAL :: B
- END SUBROUTINE F1
+ SUBROUTINE F2(B, A)
+ INTEGER :: A ; REAL :: B
+ END SUBROUTINE F1
END INTERFACE FOO
At this point, 'CALL FOO(A=1, B=1.0)' is ambiguous. */
@@ -975,7 +975,10 @@ generic_correspondence (gfc_formal_arglist *f1, gf
f2 = f2->next;
if (f2 != NULL && (compare_type_rank (f1->sym, f2->sym)
- || compare_type_rank (f2->sym, f1->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))))
goto next;
/* Now search for a disambiguating keyword argument starting at
@@ -986,7 +989,10 @@ generic_correspondence (gfc_formal_arglist *f1, gf
continue;
sym = find_keyword_arg (g->sym->name, f2_save);
- if (sym == NULL || !compare_type_rank (g->sym, sym))
+ 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))))
return 1;
}
@@ -2555,8 +2561,8 @@ compare_actual_formal (gfc_actual_arglist **ap, gf
skip_size_check:
- /* Satisfy 12.4.1.3 by ensuring that a procedure pointer actual argument
- is provided for a procedure pointer formal argument. */
+ /* Satisfy F03:12.4.1.3 by ensuring that a procedure pointer actual
+ argument is provided for a procedure pointer formal argument. */
if (f->sym->attr.proc_pointer
&& !((a->expr->expr_type == EXPR_VARIABLE
&& a->expr->symtree->n.sym->attr.proc_pointer)
@@ -2570,11 +2576,10 @@ compare_actual_formal (gfc_actual_arglist **ap, gf
return 0;
}
- /* Satisfy 12.4.1.2 by ensuring that a procedure actual argument is
+ /* Satisfy F03:12.4.1.3 by ensuring that a procedure actual argument is
provided for a procedure formal argument. */
- if (a->expr->ts.type != BT_PROCEDURE && !gfc_is_proc_ptr_comp (a->expr)
- && a->expr->expr_type == EXPR_VARIABLE
- && f->sym->attr.flavor == FL_PROCEDURE)
+ if (f->sym->attr.flavor == FL_PROCEDURE
+ && gfc_expr_attr (a->expr).flavor != FL_PROCEDURE)
{
if (where)
gfc_error ("Expected a procedure for argument '%s' at %L",
[-- Attachment #3: generic_25.f90 --]
[-- Type: application/octet-stream, Size: 565 bytes --]
! { dg-do run }
!
! PR 45521: [F08] GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
!
! Contributed by <wangmianzhi1@linuxmail.org>
interface test
procedure testAlloc
procedure testPtr
end interface
integer, allocatable :: a1
integer, pointer :: a2
if (.not.test(a1)) call abort()
if (test(a2)) call abort()
contains
logical function testAlloc(obj)
integer, allocatable :: obj
testAlloc = .true.
end function
logical function testPtr(obj)
integer, pointer :: obj
testPtr = .false.
end function
end
[-- Attachment #4: generic_26.f90 --]
[-- Type: application/octet-stream, Size: 568 bytes --]
! { dg-do compile }
! { dg-options "-std=f2003" }
!
! PR 45521: [F08] GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
!
! Contributed by <wangmianzhi1@linuxmail.org>
module a
interface test
procedure testAlloc
procedure testPtr ! { dg-error "Ambiguous interfaces" }
end interface
contains
logical function testAlloc(obj)
integer, allocatable :: obj
testAlloc = .true.
end function
logical function testPtr(obj)
integer, pointer :: obj
testPtr = .false.
end function
end
! { dg-final { cleanup-modules "a" } }
[-- Attachment #5: generic_27.f90 --]
[-- Type: application/octet-stream, Size: 625 bytes --]
! { dg-do run }
!
! PR 45521: [F08] GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE
!
! Contributed by Janus Weil <janus@gcc.gnu.org>
module m
implicit none
interface testIF
module procedure test1
module procedure test2
end interface
contains
real function test1 (obj)
real :: obj
test1 = obj
end function
real function test2 (pr)
procedure(real) :: pr
test2 = pr(0.)
end function
end module
program test
use m
implicit none
intrinsic :: cos
if (testIF(2.0)/=2.0) call abort()
if (testIF(cos)/=1.0) call abort()
end program
! { dg-final { cleanup-modules "m" } }
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-08-04 15:38 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-11 15:24 [Patch, Fortran, F08] PR 45521: GENERIC resolution with ALLOCATABLE/POINTER and PROCEDURE Janus Weil
2018-06-11 18:17 ` Steve Kargl
2018-06-11 21:15 ` Janus Weil
-- strict thread matches above, loose matches on Subject: below --
2018-08-04 14:50 Janus Weil
2018-08-04 15:14 ` Jerry DeLisle
2018-08-04 15:38 ` Janus Weil
2012-10-03 22:06 Janus Weil
2012-10-06 10:23 ` Mikael Morin
2012-10-06 12:22 ` Janus Weil
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).