public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/40593] New: Proc-pointer returning function as actual argument
@ 2009-06-29 17:29 burnus at gcc dot gnu dot org
2009-06-29 17:40 ` [Bug fortran/40593] " burnus at gcc dot gnu dot org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-29 17:29 UTC (permalink / raw)
To: gcc-bugs
Here, the proc-pointer result is passed as actual argument to a procedure which
does not want to have the pointer but the pointer target.
There are two problems: The first program shows wrong code:
sub (void (*<T3c5>) (integer(kind=4) &) f)
but passed is:
void (*<T3c5>) (integer(kind=4) &) D.1559;
D.1559 = getptr ();
sub (&D.1559);
Result: A segmentation fault.
The second program shows that the argument conformance checking goes wrong:
call sub(getPtr())
1
Error: Type mismatch in argument 'f' at (1); passed UNKNOWN to INTEGER(4)
Problem found when writing a test case for PR 40580. Please add also an
-fcheck=pointer test (assuming that PR 40580 gets checked in earlier) - I have
a test there, but it needs to be enabled
!------------ ONE -------------------
module m
contains
subroutine func(a)
integer :: a
a = 42
end subroutine func
end module m
program test
use m
implicit none
call sub(getPtr())
contains
subroutine sub(f)
procedure(func) :: f
integer :: a
call f(a)
if (a /= 42) call abort()
print *, a
end subroutine sub
function getPtr()
procedure(func), pointer :: getPtr
getPtr => func
end function getPtr
end program test
!------------ TWO -------------------
module m
contains
function func()
integer :: func
func = 42
end function func
end module m
program test
use m
implicit none
procedure(integer), pointer :: ptr
call sub(getPtr())
contains
subroutine sub(f)
procedure(integer) :: f
if (f() /= 42) call abort()
print *, f()
end subroutine sub
function getPtr()
procedure(func), pointer :: getPtr
getPtr => func
end function getPtr
end program test
--
Summary: Proc-pointer returning function as actual argument
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: wrong-code, rejects-valid
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: burnus at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/40593] Proc-pointer returning function as actual argument
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
@ 2009-06-29 17:40 ` burnus at gcc dot gnu dot org
2009-06-29 21:01 ` burnus at gcc dot gnu dot org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-29 17:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from burnus at gcc dot gnu dot org 2009-06-29 17:40 -------
Hmm, something else goes wrong, too, my fix for PR 40580 does not generate a
check (for procpointer results), it does for pointer function results and it
does for normal proc pointers. Thus, it either gets fixed automatically with
this bug, or one needs to spend some time on finding out why it does not work.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/40593] Proc-pointer returning function as actual argument
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
2009-06-29 17:40 ` [Bug fortran/40593] " burnus at gcc dot gnu dot org
@ 2009-06-29 21:01 ` burnus at gcc dot gnu dot org
2009-06-30 5:22 ` burnus at gcc dot gnu dot org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-29 21:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from burnus at gcc dot gnu dot org 2009-06-29 21:00 -------
-fcheck=pointer (remaining issues/features) is now tracked at PR 40593
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/40593] Proc-pointer returning function as actual argument
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
2009-06-29 17:40 ` [Bug fortran/40593] " burnus at gcc dot gnu dot org
2009-06-29 21:01 ` burnus at gcc dot gnu dot org
@ 2009-06-30 5:22 ` burnus at gcc dot gnu dot org
2009-07-01 8:36 ` janus at gcc dot gnu dot org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-06-30 5:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from burnus at gcc dot gnu dot org 2009-06-30 05:21 -------
> -fcheck=pointer (remaining issues/features) is now tracked at PR 40593
Ignore - that should have gone to PR 40580
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/40593] Proc-pointer returning function as actual argument
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
` (2 preceding siblings ...)
2009-06-30 5:22 ` burnus at gcc dot gnu dot org
@ 2009-07-01 8:36 ` janus at gcc dot gnu dot org
2009-07-01 8:39 ` janus at gcc dot gnu dot org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-07-01 8:36 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from janus at gcc dot gnu dot org 2009-07-01 08:35 -------
The second example in comment #0 is fixed by the following patch:
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c (revision 149129)
+++ gcc/fortran/resolve.c (working copy)
@@ -1828,7 +1828,10 @@ resolve_specific_f0 (gfc_symbol *sym, gf
found:
gfc_procedure_use (sym, &expr->value.function.actual, &expr->where);
- expr->ts = sym->ts;
+ if (sym->result)
+ expr->ts = sym->result->ts;
+ else
+ expr->ts = sym->ts;
expr->value.function.name = sym->name;
expr->value.function.esym = sym;
if (sym->as != NULL)
--
janus at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-07-01 08:35:59
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/40593] Proc-pointer returning function as actual argument
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
` (3 preceding siblings ...)
2009-07-01 8:36 ` janus at gcc dot gnu dot org
@ 2009-07-01 8:39 ` janus at gcc dot gnu dot org
2009-07-01 8:55 ` janus at gcc dot gnu dot org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-07-01 8:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from janus at gcc dot gnu dot org 2009-07-01 08:39 -------
Related problem:
module m
contains
subroutine func()
print *,"42"
end subroutine func
end module m
program test
use m
implicit none
call sub(getPtr())
contains
subroutine sub(f)
procedure(func),pointer :: f
call f()
end subroutine sub
function getPtr()
procedure(func), pointer :: getPtr
getPtr => func
end function getPtr
end program test
is rejected with:
call sub(getPtr())
1
Error: Expected a procedure pointer for argument 'f' at (1)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/40593] Proc-pointer returning function as actual argument
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
` (4 preceding siblings ...)
2009-07-01 8:39 ` janus at gcc dot gnu dot org
@ 2009-07-01 8:55 ` janus at gcc dot gnu dot org
2009-07-04 11:40 ` janus at gcc dot gnu dot org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-07-01 8:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from janus at gcc dot gnu dot org 2009-07-01 08:54 -------
The compile-time error in comment #5 is fixed by:
Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c (revision 149129)
+++ gcc/fortran/interface.c (working copy)
@@ -1911,7 +1911,10 @@ compare_actual_formal (gfc_actual_arglis
/* Satisfy 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->symtree->n.sym->attr.proc_pointer
+ && !((a->expr->expr_type == EXPR_VARIABLE
+ && a->expr->symtree->n.sym->attr.proc_pointer)
+ || (a->expr->expr_type == EXPR_FUNCTION
+ && a->expr->symtree->n.sym->result->attr.proc_pointer)
|| is_proc_ptr_comp (a->expr, NULL)))
{
if (where)
However, it still gives a runtime segfault due to:
void (*<T63>) (void) D.1556;
D.1556 = getptr ();
sub (&&D.1556);
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/40593] Proc-pointer returning function as actual argument
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
` (5 preceding siblings ...)
2009-07-01 8:55 ` janus at gcc dot gnu dot org
@ 2009-07-04 11:40 ` janus at gcc dot gnu dot org
2009-07-04 12:29 ` janus at gcc dot gnu dot org
2009-07-04 13:01 ` janus at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-07-04 11:40 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from janus at gcc dot gnu dot org 2009-07-04 11:40 -------
Mine. Patch:
http://gcc.gnu.org/ml/fortran/2009-07/msg00016.html
--
janus at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |janus at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2009-07-01 08:35:59 |2009-07-04 11:40:36
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/40593] Proc-pointer returning function as actual argument
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
` (6 preceding siblings ...)
2009-07-04 11:40 ` janus at gcc dot gnu dot org
@ 2009-07-04 12:29 ` janus at gcc dot gnu dot org
2009-07-04 13:01 ` janus at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-07-04 12:29 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from janus at gcc dot gnu dot org 2009-07-04 12:28 -------
Subject: Bug 40593
Author: janus
Date: Sat Jul 4 12:28:43 2009
New Revision: 149227
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149227
Log:
2009-07-04 Janus Weil <janus@gcc.gnu.org>
PR fortran/40593
* interface.c (compare_actual_formal): Take care of proc-pointer-valued
functions as actual arguments.
* trans-expr.c (gfc_conv_procedure_call): Ditto.
* resolve.c (resolve_specific_f0): Use the correct ts.
2009-07-04 Janus Weil <janus@gcc.gnu.org>
PR fortran/40593
* gfortran.dg/proc_ptr_result_6.f90: New.
Added:
trunk/gcc/testsuite/gfortran.dg/proc_ptr_result_6.f90
Modified:
trunk/gcc/fortran/ChangeLog
trunk/gcc/fortran/interface.c
trunk/gcc/fortran/resolve.c
trunk/gcc/fortran/trans-expr.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug fortran/40593] Proc-pointer returning function as actual argument
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
` (7 preceding siblings ...)
2009-07-04 12:29 ` janus at gcc dot gnu dot org
@ 2009-07-04 13:01 ` janus at gcc dot gnu dot org
8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2009-07-04 13:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from janus at gcc dot gnu dot org 2009-07-04 13:01 -------
Fixed with r149227. Closing.
--
janus at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40593
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2009-07-04 13:01 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-29 17:29 [Bug fortran/40593] New: Proc-pointer returning function as actual argument burnus at gcc dot gnu dot org
2009-06-29 17:40 ` [Bug fortran/40593] " burnus at gcc dot gnu dot org
2009-06-29 21:01 ` burnus at gcc dot gnu dot org
2009-06-30 5:22 ` burnus at gcc dot gnu dot org
2009-07-01 8:36 ` janus at gcc dot gnu dot org
2009-07-01 8:39 ` janus at gcc dot gnu dot org
2009-07-01 8:55 ` janus at gcc dot gnu dot org
2009-07-04 11:40 ` janus at gcc dot gnu dot org
2009-07-04 12:29 ` janus at gcc dot gnu dot org
2009-07-04 13:01 ` janus at gcc dot gnu dot 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).