This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, Fortran] PR39850: Too strict checking for procedures as actual argument
>> It was done wrongly in two test cases in the testsuite
>> (interface_21.f90 and proc_decl_8.f90).
>>
> No, that was done correctly in those cases. Contrary to this PR there is a
> ? IMPLICIT NONE
> in interface_21.f90 and proc_decl_8.f90. Thus an
> ? EXTERNAL foo
> can only refer to a SUBROUTINE.
Oops, apparently I missed this subtlety.
> In the PR 39850 (comment 0), the code has no "IMPLICIT NONE" and thus
> ? EXTERNAL foo
> means that "foo" can bei either a subroutine or a function. If "foo" is
> now passed as actual argument, it should work if the dummy argument
> accepts either a subroutine or a function (which returns a REAL) - or if
> it accepts either. Whether the dummy has an explicit interface or not
> does not play a rule.
Here goes my second attempt, which retains the error messages for
interface_21 and proc_decl_8, while avoiding the spurious error
message in the PR. I also extended the new test case interface_30.f90
a bit.
>> Regtested on x86_64-unknown-linux-gnu. Ok for trunk?
>>
> No for the reason outline above. If the actual argument is BT_UNKNOWN
> and attr.subroutine is not set, one should call gfc_set_default_type -
> then one can continue with checking whether ts.type/kind match.
Actually I don't think it would be correct to use
'gfc_set_default_type', since such a case could also be a subroutine
(which has no return type). Instead I use 'gfc_get_default_type' to
check if the symbol *could* get an implicit type, without actually
setting the type.
Regtested again. Ok now?
Cheers,
Janus
2009-06-21 Janus Weil <janus@gcc.gnu.org>
PR fortran/39850
* interface.c (gfc_compare_interfaces): Take care of implicit typing
when checking the function attribute. Plus another bugfix.
2009-06-21 Janus Weil <janus@gcc.gnu.org>
PR fortran/39850
* gfortran.dg/interface_19.f90: Add 'cleanup-modules'.
* gfortran.dg/interface_20.f90: Ditto.
* gfortran.dg/interface_21.f90: Ditto.
* gfortran.dg/interface_22.f90: Ditto.
* gfortran.dg/interface_30.f90: New.
* gfortran.dg/proc_ptr_11.f90: Fix invalid test case.
Index: gcc/testsuite/gfortran.dg/interface_22.f90
===================================================================
--- gcc/testsuite/gfortran.dg/interface_22.f90 (revision 148758)
+++ gcc/testsuite/gfortran.dg/interface_22.f90 (working copy)
@@ -23,3 +23,6 @@ module gswap
module procedure sreal, schar, sint => sreal ! { dg-error "Syntax error in MODULE PROCEDURE statement" }
end interface swap
end module gswap
+
+! { dg-final { cleanup-modules "foo g gswap" } }
+
Index: gcc/testsuite/gfortran.dg/proc_ptr_11.f90
===================================================================
--- gcc/testsuite/gfortran.dg/proc_ptr_11.f90 (revision 148758)
+++ gcc/testsuite/gfortran.dg/proc_ptr_11.f90 (working copy)
@@ -55,7 +55,7 @@ program bsp
end function add
integer function f(x)
- integer :: x
+ integer,intent(in) :: x
f = 317 + x
end function
Index: gcc/testsuite/gfortran.dg/interface_19.f90
===================================================================
--- gcc/testsuite/gfortran.dg/interface_19.f90 (revision 148758)
+++ gcc/testsuite/gfortran.dg/interface_19.f90 (working copy)
@@ -27,3 +27,6 @@ intrinsic dcos
call sub()
call sub(dcos)
end
+
+! { dg-final { cleanup-modules "m" } }
+
Index: gcc/testsuite/gfortran.dg/interface_21.f90
===================================================================
--- gcc/testsuite/gfortran.dg/interface_21.f90 (revision 148758)
+++ gcc/testsuite/gfortran.dg/interface_21.f90 (working copy)
@@ -20,3 +20,6 @@ implicit none
EXTERNAL foo ! implicit interface is undefined
call sub(foo) ! { dg-error "is not a function" }
end
+
+! { dg-final { cleanup-modules "m" } }
+
Index: gcc/testsuite/gfortran.dg/interface_20.f90
===================================================================
--- gcc/testsuite/gfortran.dg/interface_20.f90 (revision 148758)
+++ gcc/testsuite/gfortran.dg/interface_20.f90 (working copy)
@@ -18,3 +18,6 @@ implicit none
intrinsic cos
call sub(cos) ! { dg-error "wrong number of arguments" }
end
+
+! { dg-final { cleanup-modules "m" } }
+
Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c (revision 148758)
+++ gcc/fortran/interface.c (working copy)
@@ -939,7 +939,10 @@ gfc_compare_interfaces (gfc_symbol *s1,
{
gfc_formal_arglist *f1, *f2;
- if (s1->attr.function && !s2->attr.function)
+ if (s1->attr.function && (s2->attr.subroutine
+ || (!s2->attr.function
+ && s2->ts.type == BT_UNKNOWN
+ && gfc_get_default_type (s2->name, s2->ns)->type == BT_UNKNOWN)))
{
if (errmsg != NULL)
snprintf (errmsg, err_len, "'%s' is not a function", s2->name);
@@ -967,8 +970,6 @@ gfc_compare_interfaces (gfc_symbol *s1,
"of '%s'", s2->name);
return 0;
}
- if (s1->attr.if_source == IFSRC_DECL)
- return 1;
}
if (s1->attr.if_source == IFSRC_UNKNOWN
! { dg-do compile }
!
! PR39850: Too strict checking for procedures as actual argument
!
! Original test case by Tobias Burnus <burnus@gcc.gnu.org>
! Modified by Janus Weil <janus@gcc.gnu.org>
real function func()
print *,"func=42.0"
func = 42.0
end function func
program test
external func ! subroutine or implicitly typed real function
call sub(func)
call sub2(func)
contains
subroutine sub(a)
real, external :: a
print *, a(0.4)
end subroutine sub
subroutine sub2(a2)
interface
subroutine a2
end subroutine
end interface
call a2()
end subroutine
end