public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/63674] New: procedure pointer and non/pure procedure
@ 2014-10-29 11:59 valeryweber at hotmail dot com
2014-12-10 22:02 ` [Bug fortran/63674] " janus at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: valeryweber at hotmail dot com @ 2014-10-29 11:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63674
Bug ID: 63674
Summary: procedure pointer and non/pure procedure
Product: gcc
Version: 4.9.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: valeryweber at hotmail dot com
Dear All
the following code is compiling fine with 4.9.1, but shouldnt gcc complain
about calling a nonpure procedure from a pure one?
v
cat gcc_pure.f90
module test
interface
function func_interface ( ) RESULT( reslt )
INTEGER :: reslt
end function func_interface
end interface
type :: t
procedure(func_interface), nopass, pointer :: f => NULL()
end type t
contains
function func_1 ( ) RESULT( reslt )
integer :: reslt
reslt = 1
end function func_1
pure subroutine eval( a, reslt )
type(t), intent(in) :: a
integer, intent(out) :: reslt
reslt = a%f()
!reslt = func_1()
end subroutine eval
end module test
program prog
use test
type(t) :: a
integer :: reslt
a%f=>func_1
call eval(a,reslt)
write(*,*) reslt
end program prog
gfortran-4.9.1 gcc_pure.f90
./a.out
1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/63674] procedure pointer and non/pure procedure
2014-10-29 11:59 [Bug fortran/63674] New: procedure pointer and non/pure procedure valeryweber at hotmail dot com
@ 2014-12-10 22:02 ` janus at gcc dot gnu.org
2014-12-10 22:12 ` janus at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2014-12-10 22:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63674
janus at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-12-10
CC| |janus at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from janus at gcc dot gnu.org ---
(In reply to Valery Weber from comment #0)
> the following code is compiling fine with 4.9.1, but shouldnt gcc complain
> about calling a nonpure procedure from a pure one?
It definitely should, and the problem also occurs with the 5.0 trunk.
The part that checks for pureness in 'resolve_function' is apparently not
applied to procedure-pointer components, but could e.g. be transferred to
'resolve_expr_ppc' like this:
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (Revision 218598)
+++ gcc/fortran/resolve.c (Arbeitskopie)
@@ -6048,6 +6048,7 @@ static bool
resolve_expr_ppc (gfc_expr* e)
{
gfc_component *comp;
+ const char *name = NULL;
comp = gfc_get_proc_ptr_comp (e);
gcc_assert (comp != NULL);
@@ -6074,6 +6075,32 @@ resolve_expr_ppc (gfc_expr* e)
if (!update_ppc_arglist (e))
return false;
+ if (!pure_function (e, &name))
+ {
+ if (forall_flag)
+ {
+ gfc_error ("Reference to non-PURE function '%s' at %L inside a "
+ "FORALL %s", comp->name, &e->where,
+ forall_flag == 2 ? "mask" : "block");
+ return false;
+ }
+ else if (gfc_do_concurrent_flag)
+ {
+ gfc_error ("Reference to non-PURE function '%s' at %L inside a "
+ "DO CONCURRENT %s", comp->name, &e->where,
+ gfc_do_concurrent_flag == 2 ? "mask" : "block");
+ return false;
+ }
+ else if (gfc_pure (NULL))
+ {
+ gfc_error ("Reference to non-PURE function '%s' at %L "
+ "within a PURE procedure", comp->name, &e->where);
+ return false;
+ }
+
+ gfc_unset_implicit_pure (NULL);
+ }
+
gfc_ppc_use (comp, &e->value.compcall.actual, &e->where);
return true;
This is sufficient to trigger the right error for the test case, but more work
needs to be done: 'pure_function' needs to be taught to handle PPCs and one
needs to add a pureness check for procedure-pointer assignments. Finally it
should be checked if the same problem also applies to 'ordinary' procedure
pointers (which are not a type component) and to the case of subroutines
(instead of functions).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/63674] procedure pointer and non/pure procedure
2014-10-29 11:59 [Bug fortran/63674] New: procedure pointer and non/pure procedure valeryweber at hotmail dot com
2014-12-10 22:02 ` [Bug fortran/63674] " janus at gcc dot gnu.org
@ 2014-12-10 22:12 ` janus at gcc dot gnu.org
2014-12-10 22:18 ` janus at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2014-12-10 22:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63674
--- Comment #2 from janus at gcc dot gnu.org ---
Test case for ordinary procedure pointers:
module test
interface
function func_interface ( ) RESULT( reslt )
INTEGER :: reslt
end function func_interface
end interface
contains
function func_1 ( ) RESULT( reslt )
integer :: reslt
reslt = 1
end function func_1
pure subroutine eval( reslt )
integer, intent(out) :: reslt
procedure(func_interface), pointer :: f
f=>func_1
reslt = f()
! reslt = func_1()
end subroutine eval
end module test
program prog
use test
integer :: reslt
call eval(reslt)
write(*,*) reslt
end program prog
This gives the expected error message with 4.9 and trunk, which shows that the
problem only occurs for PPCs.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/63674] procedure pointer and non/pure procedure
2014-10-29 11:59 [Bug fortran/63674] New: procedure pointer and non/pure procedure valeryweber at hotmail dot com
2014-12-10 22:02 ` [Bug fortran/63674] " janus at gcc dot gnu.org
2014-12-10 22:12 ` janus at gcc dot gnu.org
@ 2014-12-10 22:18 ` janus at gcc dot gnu.org
2014-12-14 9:33 ` [Bug fortran/63674] [F03] " janus at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2014-12-10 22:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63674
--- Comment #3 from janus at gcc dot gnu.org ---
Another test case, this time for a PPC pointing to a subroutine:
module test
interface
subroutine sub_interface ( )
end subroutine
end interface
type :: t
procedure(sub_interface), nopass, pointer :: s => NULL()
end type t
contains
subroutine sub_1 ( )
end subroutine
pure subroutine eval( a )
type(t), intent(in) :: a
call a%s()
! call sub_1()
end subroutine eval
end module test
program prog
use test
type(t) :: a
a%s=>sub_1
call eval(a)
end program prog
Should give an error, but is accepted by 4.9 and trunk (even with the patch in
comment #1).
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/63674] [F03] procedure pointer and non/pure procedure
2014-10-29 11:59 [Bug fortran/63674] New: procedure pointer and non/pure procedure valeryweber at hotmail dot com
` (2 preceding siblings ...)
2014-12-10 22:18 ` janus at gcc dot gnu.org
@ 2014-12-14 9:33 ` janus at gcc dot gnu.org
2014-12-14 12:05 ` janus at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2014-12-14 9:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63674
janus at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/63674] [F03] procedure pointer and non/pure procedure
2014-10-29 11:59 [Bug fortran/63674] New: procedure pointer and non/pure procedure valeryweber at hotmail dot com
` (3 preceding siblings ...)
2014-12-14 9:33 ` [Bug fortran/63674] [F03] " janus at gcc dot gnu.org
@ 2014-12-14 12:05 ` janus at gcc dot gnu.org
2014-12-14 12:07 ` janus at gcc dot gnu.org
2014-12-15 10:35 ` janus at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2014-12-14 12:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63674
--- Comment #4 from janus at gcc dot gnu.org ---
Author: janus
Date: Sun Dec 14 12:04:49 2014
New Revision: 218717
URL: https://gcc.gnu.org/viewcvs?rev=218717&root=gcc&view=rev
Log:
2014-12-14 Janus Weil <janus@gcc.gnu.org>
PR fortran/63674
* resolve.c (pure_function): Treat procedure-pointer components.
(check_pure_function): New function.
(resolve_function): Use it.
(pure_subroutine): Return a bool to indicate success and modify
arguments.
(resolve_generic_s0,resolve_specific_s0,resolve_unknown_s): Use return
value of 'pure_subroutine'.
(resolve_ppc_call): Call 'pure_subroutine'.
(resolve_expr_ppc): Call 'check_pure_function'.
2014-12-14 Janus Weil <janus@gcc.gnu.org>
PR fortran/63674
* gfortran.dg/proc_ptr_comp_39.f90: New.
* gfortran.dg/pure_dummy_length_1.f90: Modified error message.
* gfortran.dg/stfunc_6.f90: Ditto.
* gfortran.dg/typebound_operator_4.f90: Ditto.
Added:
trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_39.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/resolve.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gfortran.dg/pure_dummy_length_1.f90
trunk/gcc/testsuite/gfortran.dg/stfunc_6.f90
trunk/gcc/testsuite/gfortran.dg/typebound_operator_4.f03
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/63674] [F03] procedure pointer and non/pure procedure
2014-10-29 11:59 [Bug fortran/63674] New: procedure pointer and non/pure procedure valeryweber at hotmail dot com
` (4 preceding siblings ...)
2014-12-14 12:05 ` janus at gcc dot gnu.org
@ 2014-12-14 12:07 ` janus at gcc dot gnu.org
2014-12-15 10:35 ` janus at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2014-12-14 12:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63674
janus at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #5 from janus at gcc dot gnu.org ---
Fixed with r218717. Closing. Thanks for the report!
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug fortran/63674] [F03] procedure pointer and non/pure procedure
2014-10-29 11:59 [Bug fortran/63674] New: procedure pointer and non/pure procedure valeryweber at hotmail dot com
` (5 preceding siblings ...)
2014-12-14 12:07 ` janus at gcc dot gnu.org
@ 2014-12-15 10:35 ` janus at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: janus at gcc dot gnu.org @ 2014-12-15 10:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63674
--- Comment #6 from janus at gcc dot gnu.org ---
Author: janus
Date: Mon Dec 15 10:34:46 2014
New Revision: 218738
URL: https://gcc.gnu.org/viewcvs?rev=218738&root=gcc&view=rev
Log:
2014-12-15 Janus Weil <janus@gcc.gnu.org>
PR fortran/63674
* resolve.c (check_pure_function): Rewording in error message.
2014-12-15 Janus Weil <janus@gcc.gnu.org>
PR fortran/63674
* gfortran.dg/forall_5.f90: Modified error message.
* gfortran.dg/proc_ptr_comp_39.f90: Ditto.
* gfortran.dg/pure_dummy_length_1.f90: Ditto.
* gfortran.dg/stfunc_6.f90: Ditto.
* gfortran.dg/typebound_operator_4.f90: Ditto.
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/resolve.c
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/gfortran.dg/forall_5.f90
trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_39.f90
trunk/gcc/testsuite/gfortran.dg/pure_dummy_length_1.f90
trunk/gcc/testsuite/gfortran.dg/stfunc_6.f90
trunk/gcc/testsuite/gfortran.dg/typebound_operator_4.f03
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-12-15 10:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-29 11:59 [Bug fortran/63674] New: procedure pointer and non/pure procedure valeryweber at hotmail dot com
2014-12-10 22:02 ` [Bug fortran/63674] " janus at gcc dot gnu.org
2014-12-10 22:12 ` janus at gcc dot gnu.org
2014-12-10 22:18 ` janus at gcc dot gnu.org
2014-12-14 9:33 ` [Bug fortran/63674] [F03] " janus at gcc dot gnu.org
2014-12-14 12:05 ` janus at gcc dot gnu.org
2014-12-14 12:07 ` janus at gcc dot gnu.org
2014-12-15 10:35 ` janus at gcc dot gnu.org
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).