diff options
author | Andre Vehreschild <vehre@gcc.gnu.org> | 2024-06-06 14:01:13 +0200 |
---|---|---|
committer | Andre Vehreschild <vehre@gcc.gnu.org> | 2024-06-19 10:39:56 +0200 |
commit | dbb718175d7df89b957b316ba2f5fbea5d21b2b1 (patch) | |
tree | 9ced42911ff7d3df14030a26945dc925b47dcbf8 /gcc/fortran/trans-decl.cc | |
parent | 23141088e8fb50bf916ac0b2e364b1eef9f3569d (diff) | |
download | gcc-dbb718175d7df89b957b316ba2f5fbea5d21b2b1.zip gcc-dbb718175d7df89b957b316ba2f5fbea5d21b2b1.tar.gz gcc-dbb718175d7df89b957b316ba2f5fbea5d21b2b1.tar.bz2 |
Fortran: Set the vptr of a class typed result.
PR fortran/90076
gcc/fortran/ChangeLog:
* trans-decl.cc (gfc_generate_function_code): Set vptr for
results to declared class type.
* trans-expr.cc (gfc_reset_vptr): Allow to provide the typespec
instead of the expression.
* trans.h (gfc_reset_vptr): Same.
gcc/testsuite/ChangeLog:
* gfortran.dg/class_76.f90: Add declared vtab occurrence.
* gfortran.dg/class_78.f90: New test.
Diffstat (limited to 'gcc/fortran/trans-decl.cc')
-rw-r--r-- | gcc/fortran/trans-decl.cc | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc index dca7779..8853871 100644 --- a/gcc/fortran/trans-decl.cc +++ b/gcc/fortran/trans-decl.cc @@ -7926,11 +7926,12 @@ gfc_generate_function_code (gfc_namespace * ns) && CLASS_DATA (sym)->attr.dimension == 0 && sym->result == sym) { - tmp = CLASS_DATA (sym)->backend_decl; - tmp = fold_build3_loc (input_location, COMPONENT_REF, - TREE_TYPE (tmp), result, tmp, NULL_TREE); - gfc_add_modify (&init, tmp, fold_convert (TREE_TYPE (tmp), - null_pointer_node)); + tmp = gfc_class_data_get (result); + gfc_add_modify (&init, tmp, + fold_convert (TREE_TYPE (tmp), + null_pointer_node)); + gfc_reset_vptr (&init, nullptr, result, + CLASS_DATA (sym->result)->ts.u.derived); } else if (sym->ts.type == BT_DERIVED && !sym->attr.allocatable) |