This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, Fortran] Fix DECL of namelist I/O function; fix FINALIZATION
- From: Tobias Burnus <burnus at net-b dot de>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Sat, 16 Aug 2014 00:10:09 +0200
- Subject: [Patch, Fortran] Fix DECL of namelist I/O function; fix FINALIZATION
- Authentication-results: sourceware.org; auth=none
This patch fixes two minor issues
a) The argument issue mentioned in
https://gcc.gnu.org/ml/fortran/2014-08/msg00007.html
The main issue is that the decl uses "void" as argument; the FE passes
IARG() alias gfc_array_index_type while the library expects a
GFC_INTEGER_4. As n_dim and ts->kind are small, I have chosen to keep
GFC_INTEGER_4 in the library and use int32_t for the argument and in the
decl.
b) resolve_finalizer calls at the end the function, which obtains the
vtab, which in turns calls the vtab function of the parent, which tries
to generate the _final entry, which requires that the finalizers are
resolved. In the test case, the parent's finalizer wasn't ready, leading
to an ICE in an assert. The patch now first resolves the parent's
finalizers before taking care of its own.
Build and regtested on x86-64-gnu-linux.
OK for the trunk?
Tobias
2014-08-15 Tobias Burnus <burnus@net-b.de>
* trans-io.c (gfc_build_io_library_fndecls): Fix decl of
IOCALL_SET_NML_VAL.
(transfer_namelist_element): Use proper int type as argument.
diff --git a/gcc/fortran/trans-io.c b/gcc/fortran/trans-io.c
index cbe54ab..4340afb 100644
--- a/gcc/fortran/trans-io.c
+++ b/gcc/fortran/trans-io.c
@@ -467,7 +467,7 @@ gfc_build_io_library_fndecls (void)
iocall[IOCALL_SET_NML_VAL] = gfc_build_library_function_decl_with_spec (
get_identifier (PREFIX("st_set_nml_var")), ".w.R",
void_type_node, 6, dt_parm_type, pvoid_type_node, pvoid_type_node,
- void_type_node, gfc_charlen_type_node, gfc_int4_type_node);
+ gfc_int4_type_node, gfc_charlen_type_node, gfc_int4_type_node);
iocall[IOCALL_SET_NML_VAL_DIM] = gfc_build_library_function_decl_with_spec (
get_identifier (PREFIX("st_set_nml_var_dim")), ".w",
@@ -1557,6 +1557,7 @@ transfer_namelist_element (stmtblock_t * block, const char * var_name,
tree dtype;
tree dt_parm_addr;
tree decl = NULL_TREE;
+ tree gfc_int4_type_node = gfc_get_int_type (4);
int n_dim;
int itype;
int rank = 0;
@@ -1605,7 +1606,8 @@ transfer_namelist_element (stmtblock_t * block, const char * var_name,
tmp = build_call_expr_loc (input_location,
iocall[IOCALL_SET_NML_VAL], 6,
dt_parm_addr, addr_expr, string,
- IARG (ts->kind), tmp, dtype);
+ build_int_cst (gfc_int4_type_node, ts->kind),
+ tmp, dtype);
gfc_add_expr_to_block (block, tmp);
/* If the object is an array, transfer rank times:
@@ -1616,7 +1618,7 @@ transfer_namelist_element (stmtblock_t * block, const char * var_name,
tmp = build_call_expr_loc (input_location,
iocall[IOCALL_SET_NML_VAL_DIM], 5,
dt_parm_addr,
- IARG (n_dim),
+ build_int_cst (gfc_int4_type_node, n_dim),
gfc_conv_array_stride (decl, n_dim),
gfc_conv_array_lbound (decl, n_dim),
gfc_conv_array_ubound (decl, n_dim));
2014-08-15 Tobias Burnus <burnus@net-b.de>
* resolve.c (gfc_resolve_finalizers): Ensure that parents are
resolved first.
2014-08-15 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/finalize_27.f90: New.
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index ea28ef4..32ff9dd 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -11416,6 +11416,10 @@ gfc_resolve_finalizers (gfc_symbol* derived, bool *finalizable)
bool seen_scalar = false;
gfc_symbol *vtab;
gfc_component *c;
+ gfc_symbol *parent = gfc_get_derived_super_type (derived);
+
+ if (parent)
+ gfc_resolve_finalizers (parent, finalizable);
/* Return early when not finalizable. Additionally, ensure that derived-type
components have a their finalizables resolved. */
diff --git a/gcc/testsuite/gfortran.dg/finalize_27.f90 b/gcc/testsuite/gfortran.dg/finalize_27.f90
new file mode 100644
index 0000000..bdc7c45
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/finalize_27.f90
@@ -0,0 +1,25 @@
+! { dg-do compile }
+!
+! Was ICEing before
+!
+! Contributed by Reinhold Bader
+!
+
+module mod_fin_04
+ implicit none
+ type :: p_vec
+ contains
+ final :: delete
+ end type p_vec
+ type, extends(p_vec) :: bar
+ contains
+ final :: del2
+ end type bar
+contains
+ subroutine delete(this)
+ type(p_vec) :: this
+ end subroutine delete
+ subroutine del2(this)
+ type(bar) :: this
+ end subroutine del2
+end module