Bug 41706 - [OOP] Calling one TBP as an actual argument of another TBP
Summary: [OOP] Calling one TBP as an actual argument of another TBP
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2009-10-14 13:33 UTC by janus
Modified: 2009-10-21 09:01 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description janus 2009-10-14 13:33:40 UTC
Consider the following code:

module m

type :: t
contains
  procedure, nopass :: a
  procedure, nopass :: b
end type

contains

  real function a (x)
    real :: x
    a = 2.*x
  end function

  real function b (x)
    real :: x
    b = 3.*x
  end function

  subroutine s
    class(t),allocatable :: x
    real :: r
    allocate(x)
    r = x%a (1.1)	! works
    r = x%a ( b(1.2))	! works
    r = b ( x%a (1.3))	! works
    r = x%a(x%b(1.4))	! fails
  end subroutine

end


The line marked with "fails" triggers the following error (with trunk r152720):

end
   1
Internal Error at (1):
free_expr0(): Bad expr type


Backtrace:

Breakpoint 1, free_expr0 (e=0x1bd70e0) at /home/jweil/gcc45/trunk/gcc/fortran/expr.c:209
209           gfc_internal_error ("free_expr0(): Bad expr type");
(gdb) bt
#0  free_expr0 (e=0x1bd70e0) at /home/jweil/gcc45/trunk/gcc/fortran/expr.c:209
#1  0x00000000004c54ba in gfc_free_expr (e=0x1bd70e0) at /home/jweil/gcc45/trunk/gcc/fortran/expr.c:236
#2  0x000000000051e205 in resolve_class_compcall (e=0x1bd47f0) at /home/jweil/gcc45/trunk/gcc/fortran/resolve.c:5237
#3  0x000000000051e6d3 in gfc_resolve_expr (e=0x1bd47f0) at /home/jweil/gcc45/trunk/gcc/fortran/resolve.c:5391
#4  0x0000000000522405 in resolve_code (code=0x1bd5330, ns=0x1bd1ea0) at /home/jweil/gcc45/trunk/gcc/fortran/resolve.c:7601
#5  0x000000000052b5fb in resolve_codes (ns=0x1bd1ea0) at /home/jweil/gcc45/trunk/gcc/fortran/resolve.c:11931
#6  0x000000000052b518 in resolve_codes (ns=0x1bce0d0) at /home/jweil/gcc45/trunk/gcc/fortran/resolve.c:11921
#7  0x000000000052b6f0 in gfc_resolve (ns=0x1bce0d0) at /home/jweil/gcc45/trunk/gcc/fortran/resolve.c:11958
#8  0x000000000050dd80 in gfc_parse_file () at /home/jweil/gcc45/trunk/gcc/fortran/parse.c:4195
#9  0x000000000054aaf4 in gfc_be_parse_file (set_yydebug=0) at /home/jweil/gcc45/trunk/gcc/fortran/f95-lang.c:239
#10 0x00000000009b492d in compile_file () at /home/jweil/gcc45/trunk/gcc/toplev.c:1049
#11 0x00000000009b6c19 in do_compile () at /home/jweil/gcc45/trunk/gcc/toplev.c:2408
#12 0x00000000009b6cda in toplev_main (argc=2, argv=0x7fff1c893c48) at /home/jweil/gcc45/trunk/gcc/toplev.c:2450
#13 0x00000000005c814f in main (argc=2, argv=0x7fff1c893c48) at /home/jweil/gcc45/trunk/gcc/main.c:35
Comment 1 Paul Thomas 2009-10-20 04:17:03 UTC
Subject: Bug 41706

Author: pault
Date: Tue Oct 20 04:16:02 2009
New Revision: 153004

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153004
Log:
2009-10-20  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41706
	* resolve.c (resolve_arg_exprs): New function.
	(resolve_class_compcall): Call the above.
	(resolve_class_typebound_call): The same.

2009-10-20  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/41706
	* gfortran.dg/class_9 : New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/class_9.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 2 Paul Thomas 2009-10-20 04:52:41 UTC
Fixed on trunk.

Thanks for the report!

Paul
Comment 3 janus 2009-10-20 11:30:20 UTC
Reopening. Salvatore's code still fails with the same error, which is due to the analogous case with a subroutine:

module m

type :: t
contains
  procedure, nopass :: a
  procedure, nopass :: b
end type

contains

  subroutine a (x)
    real :: x
    print *,x
  end subroutine

  real function b ()
    b = 3.
  end function

  subroutine s
    class(t),allocatable :: x
    real :: r
    allocate(x)
    call x%a(x%b())   ! fails
  end subroutine

end
Comment 4 paul.richard.thomas@gmail.com 2009-10-20 12:19:19 UTC
Subject: Re:  [OOP] Calling one TBP as an actual argument 
	of another TBP

Oh bother!  I completely forgot to test the subroutine branch - thanks Janus

On Tue, Oct 20, 2009 at 1:30 PM, janus at gcc dot gnu dot org
<gcc-bugzilla@gcc.gnu.org> wrote:
>
>
> ------- Comment #3 from janus at gcc dot gnu dot org  2009-10-20 11:30 -------
> Reopening. Salvatore's code still fails with the same error, which is due to
> the analogous case with a subroutine:
>
> module m
>
> type :: t
> contains
>  procedure, nopass :: a
>  procedure, nopass :: b
> end type
>
> contains
>
>  subroutine a (x)
>    real :: x
>    print *,x
>  end subroutine
>
>  real function b ()
>    b = 3.
>  end function
>
>  subroutine s
>    class(t),allocatable :: x
>    real :: r
>    allocate(x)
>    call x%a(x%b())   ! fails
>  end subroutine
>
> end
>
>
> --
>
> janus at gcc dot gnu dot org changed:
>
>           What    |Removed                     |Added
> ----------------------------------------------------------------------------
>             Status|RESOLVED                    |UNCONFIRMED
>         Resolution|FIXED                       |
>
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41706
>
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.
>



Comment 5 janus 2009-10-20 12:29:31 UTC
(In reply to comment #4)
> Oh bother!  I completely forgot to test the subroutine branch - thanks Janus

But in your patch you do the argument resolution both in resolve_class_compcall and resolve_class_typebound_call, which should take care of type-bound functions *and* subroutines, shouldn't it? Therefore I don't see why it still fails for subroutines ...
Comment 6 janus 2009-10-21 08:57:11 UTC
Subject: Bug 41706

Author: janus
Date: Wed Oct 21 08:56:56 2009
New Revision: 153049

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=153049
Log:
2009-10-21  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41706
	PR fortran/41766
	* match.c (select_type_set_tmp): Set flavor for temporary.
	* resolve.c (resolve_class_typebound_call): Correctly resolve actual
	arguments.


2009-10-21  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41706
	PR fortran/41766
	* gfortran.dg/class_9.f03: Extended test case.
	* gfortran.dg/select_type_7.f03: New test case.

Added:
    trunk/gcc/testsuite/gfortran.dg/select_type_7.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/match.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/class_9.f03

Comment 7 janus 2009-10-21 09:01:46 UTC
Fixed with r153049. Closing.