Bug 44558 - [OOP] ICE on invalid code: called TBP subroutine as TBP function
Summary: [OOP] ICE on invalid code: called TBP subroutine as TBP function
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-16 15:25 UTC by Hans-Werner Boschmann
Modified: 2010-06-17 22:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-06-16 20:58:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hans-Werner Boschmann 2010-06-16 15:25:01 UTC
module ice5
  type::a_type
   contains  
     procedure::a_subroutine_1
     procedure::a_subroutine_2
  end type a_type
contains
  subroutine a_subroutine_1(this)
    class(a_type)::this
    real::res
    res=this%a_subroutine_2()
  end subroutine a_subroutine_1
  subroutine a_subroutine_2(this)
    class(a_type)::this
  end subroutine a_subroutine_2
end module ice5


gfortran -c ice5.f03
ice5.f03:11.8:

    res=this%a_subroutine_2()
        1
Fehler: 'a_subroutine_2' at (1) should be a FUNCTION
f951: interner Compiler-Fehler: in gfc_add_component_ref, bei fortran/class.c:77


Obvioulsly the code is nonsense and the compiler generates a proper error message, so there is little need to fix this ICE. However, it is an ICE.
Comment 1 janus 2010-06-16 20:50:20 UTC
Confirmed. Btw the same thing happens if you treat a type-bound function as if it were a subroutine:

module ice5
  type::a_type
   contains  
     procedure::a_subroutine_1
     procedure::a_subroutine_2
  end type a_type
contains
  real function a_subroutine_1(this)
    class(a_type)::this
    real::res
    !res=this%a_subroutine_2()
  end function
  subroutine a_subroutine_2(this)
    class(a_type)::this
    call this%a_subroutine_1()
  end subroutine
end module ice5



Error: 'a_subroutine_1' at (1) should be a SUBROUTINE
f951: internal compiler error: in gfc_add_component_ref, at fortran/class.c:77
Comment 2 janus 2010-06-16 20:58:36 UTC
This is easily fixed by the following patch:


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(revision 160833)
+++ gcc/fortran/resolve.c	(working copy)
@@ -5498,7 +5498,8 @@ resolve_typebound_function (gfc_expr* e)
 
   /* Treat the call as if it is a typebound procedure, in order to roll
      out the correct name for the specific function.  */
-  resolve_compcall (e, &name);
+  if (resolve_compcall (e, &name) == FAILURE)
+    return FAILURE;
   ts = e->ts;
 
   /* Then convert the expression to a procedure pointer component call.  */
@@ -5571,7 +5572,8 @@ resolve_typebound_subroutine (gfc_code *code)
   if (code->expr1->value.compcall.tbp->is_generic)
     genname = code->expr1->value.compcall.name;
 
-  resolve_typebound_call (code, &name);
+  if (resolve_typebound_call (code, &name) == FAILURE)
+    return FAILURE;
   ts = code->expr1->ts;
 
   /* Then convert the expression to a procedure pointer component call.  */



I will regtest this now and in case of success commit it as obvious later ...
Comment 3 janus 2010-06-17 22:15:48 UTC
Subject: Bug 44558

Author: janus
Date: Thu Jun 17 22:15:30 2010
New Revision: 160948

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=160948
Log:
2010-06-17  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44558
	* resolve.c (resolve_typebound_function,resolve_typebound_subroutine):
	Return directly in case of an error.


2010-06-17  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/44558
	* gfortran.dg/typebound_call_15.f03: New.

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

Comment 4 janus 2010-06-17 22:18:15 UTC
Fixed with r160948. Closing.

Thanks for the report!