Fortran: Delay vtab generation until after parsing [PR92587]
gcc/fortran/ChangeLog:
PR fortran/92587
* match.c (gfc_match_assignment): Move gfc_find_vtab call from here ...
* resolve.c (gfc_resolve_code): ... to here.
gcc/testsuite/ChangeLog:
PR fortran/92587
* gfortran.dg/finalize_37.f90: New test.
gcc/fortran/match.c | 3 --
gcc/fortran/resolve.c | 3 ++
gcc/testsuite/gfortran.dg/finalize_37.f90 | 51 ++++++++++++++++++++++++++++
4 files changed, 80 insertions(+), 3 deletions(-)
@@ -1389,9 +1389,6 @@ gfc_match_assignment (void)
gfc_check_do_variable (lvalue->symtree);
- if (lvalue->ts.type == BT_CLASS)
- gfc_find_vtab (&rvalue->ts);
-
return MATCH_YES;
}
@@ -11896,6 +11896,9 @@ start:
if (!t)
break;
+ if (code->expr1->ts.type == BT_CLASS)
+ gfc_find_vtab (&code->expr2->ts);
+
/* Remove a GFC_ISYM_CAF_GET inserted for a coindexed variable on
the LHS. */
if (code->expr1->expr_type == EXPR_FUNCTION
new file mode 100644
@@ -0,0 +1,51 @@
+! { dg-do compile }
+! { dg-additional-options "-fdump-tree-original" }
+!
+! PR fortran/92587
+!
+
+module m
+ implicit none (type, external)
+ type t2
+ contains
+ final :: fini
+ end type
+ type t3
+ type(t2) :: a
+ end type
+ type, extends(t3) :: t4
+ end type
+ class(t4), allocatable :: y
+ class(t4), allocatable :: z
+contains
+ subroutine sub
+ y = z
+ end
+ subroutine fini(x)
+ type(t2) :: x
+ end
+end
+
+module m2
+ use m
+ implicit none (type, external)
+ type, extends(t3) :: t5
+ end type
+ type, extends(t3) :: t6
+ contains
+ final :: fin2
+ end type
+contains
+ subroutine bar(x, y, z)
+ class(t4), allocatable, intent(out) :: x
+ class(t5), allocatable, intent(out) :: y
+ class(t6), allocatable, intent(out) :: z
+ end
+ subroutine fin2 (x)
+ type(t6) :: x
+ end
+end
+
+! { dg-final { scan-tree-dump "__final_m_T2 \\\(struct" "original" } }
+! { dg-final { scan-tree-dump "__final_m_T3 \\\(struct" "original" } }
+! { dg-final { scan-tree-dump "__final_m2_T6 \\\(struct" "original" } }