Bug 45674

Summary: [OOP] Undefined references for extended types
Product: gcc Reporter: Dietmar Ebner <dietmar.ebner>
Component: fortranAssignee: janus
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, janus
Priority: P3    
Version: 4.6.0   
Target Milestone: 4.6.0   
Host: i686-pc-linux-gnu Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu Known to work:
Known to fail: Last reconfirmed: 2010-09-16 12:10:46

Description Dietmar Ebner 2010-09-14 23:48:54 UTC
The testcase below leads to the following linker error on current trunk, gcc 4.5.0 and gcc 4.5.1: 
$gfortran fails.f90
/tmp/ccG09ce7.o: In function `__fails_test_MOD_bar':
fails.f90:(.text+0xe): undefined reference to `vtab$b_t.1500'
collect2: ld returned 1 exit status

The patch at the end of the bug report seems to solve the problem for me but it's mainly a wild guess. The issue seems to be closely related to 44065.

file fails.f90
===================================================================
module fails_mod
  implicit none 
  type :: a_t
     integer :: a
  end type
  type, extends(a_t) :: b_t
     integer :: b
  end type
contains
  subroutine foo(a)
    class(a_t) :: a
  end subroutine foo
end module fails_mod

module fails_test
  implicit none
contains
  subroutine bar
    use fails_mod
    type(b_t) :: b
    call foo(b)
  end subroutine bar
end module fails_test

end


Index: fortran/interface.c
===================================================================
--- fortran/interface.c (revision 164288)
+++ fortran/interface.c (working copy)
@@ -1428,10 +1428,12 @@
       && actual->ts.u.derived && actual->ts.u.derived->ts.is_iso_c)
     return 1;
 
-  if (formal->ts.type == BT_CLASS)
+  if (formal->ts.type == BT_CLASS) {
     /* Make sure the vtab symbol is present when
        the module variables are generated.  */
     gfc_find_derived_vtab (formal->ts.u.derived);
+    gfc_find_derived_vtab (actual->ts.u.derived);
+  }
 
   if (actual->ts.type == BT_PROCEDURE)
     {
Comment 1 janus 2010-09-15 13:57:41 UTC
Confirmed. From a quick glimpse it seems the patch goes in the right direction. Will have a closer look soon.
Comment 2 janus 2010-09-15 14:46:07 UTC
(In reply to comment #0)
> Index: fortran/interface.c
> ===================================================================
> --- fortran/interface.c (revision 164288)
> +++ fortran/interface.c (working copy)
> @@ -1428,10 +1428,12 @@
>        && actual->ts.u.derived && actual->ts.u.derived->ts.is_iso_c)
>      return 1;
> 
> -  if (formal->ts.type == BT_CLASS)
> +  if (formal->ts.type == BT_CLASS) {
>      /* Make sure the vtab symbol is present when
>         the module variables are generated.  */
>      gfc_find_derived_vtab (formal->ts.u.derived);
> +    gfc_find_derived_vtab (actual->ts.u.derived);
> +  }
> 
>    if (actual->ts.type == BT_PROCEDURE)
>      {
> 

Actually I think this patch is ok. Are you interested in committing it yourself? [Note that you'll need an FSF copyright assignment, if you don't already have one.] Otherwise I can commit it for you.

Side note: One can (should) extend the patch in the following way ...

Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c     (revision 164304)
+++ gcc/fortran/interface.c     (working copy)
@@ -1428,10 +1428,10 @@ compare_parameter (gfc_symbol *formal, gfc_expr *a
       && actual->ts.u.derived && actual->ts.u.derived->ts.is_iso_c)
     return 1;
 
-  if (formal->ts.type == BT_CLASS)
+  if (formal->ts.type == BT_CLASS && actual->ts.type == BT_DERIVED)
     /* Make sure the vtab symbol is present when
        the module variables are generated.  */
-    gfc_find_derived_vtab (formal->ts.u.derived);
+    gfc_find_derived_vtab (actual->ts.u.derived);
 
   if (actual->ts.type == BT_PROCEDURE)
     {


(I have not regtested this yet.)
Comment 3 Dietmar Ebner 2010-09-15 15:36:27 UTC
(In reply to comment #2)
> Actually I think this patch is ok. Are you interested in committing it
> yourself? [Note that you'll need an FSF copyright assignment, if you don't
> already have one.] Otherwise I can commit it for you.
I don't have the copyright assignment in place so please go ahead and do it.

Thanks for the quick fix!
Comment 4 Dominique d'Humieres 2010-09-16 08:50:19 UTC
> (I have not regtested this yet.)

The (second) patch in comment #2 fixes the pr without regression.
Comment 5 janus 2010-09-16 12:10:46 UTC
(In reply to comment #3)
> Thanks for the quick fix!

Well, it was *your* fix, so *I* should thank *you* :)

Anyway, I think the patch in comment #2 qualifies as obvious, and has no regressions, as noted by Dominique. Will commit soon.
Comment 6 janus 2010-09-16 13:13:15 UTC
Subject: Bug 45674

Author: janus
Date: Thu Sep 16 13:12:59 2010
New Revision: 164338

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

	PR fortran/45674
	* interface.c (compare_parameter): Create vtab for actual argument,
	instead of formal (if needed).


2010-09-16  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/45674
	* gfortran.dg/class_dummy_2.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_dummy_2.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/interface.c
    trunk/gcc/testsuite/ChangeLog

Comment 7 janus 2010-09-16 13:14:21 UTC
Fixed with r164338. Closing.

Thanks for the report!