From afc44c790e40aef3658d910789c569382defc006 Mon Sep 17 00:00:00 2001 From: janus Date: Wed, 5 Jan 2011 09:05:44 +0000 Subject: [PATCH] 2011-01-05 Janus Weil PR fortran/47024 * trans-decl.c (gfc_trans_deferred_vars): Initialize the _vpr component of polymorphic allocatables according to their declared type. 2011-01-05 Janus Weil PR fortran/47024 * gfortran.dg/storage_size_3.f08: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@168505 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/trans-decl.c | 21 ++++++++++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/storage_size_3.f08 | 12 ++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/storage_size_3.f08 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 800fc3a..13cda02 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2011-01-05 Janus Weil + + PR fortran/47024 + * trans-decl.c (gfc_trans_deferred_vars): Initialize the _vpr component + of polymorphic allocatables according to their declared type. + 2011-01-04 Janus Weil PR fortran/46448 diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index b9c1416..829548c 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -3312,7 +3312,7 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block) { /* Nullify and automatic deallocation of allocatable scalars. */ - tree tmp; + tree tmp = NULL; gfc_expr *e; gfc_se se; stmtblock_t init; @@ -3337,8 +3337,23 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block) if (!sym->attr.result) tmp = gfc_deallocate_scalar_with_status (se.expr, NULL, true, NULL, sym->ts); - else - tmp = NULL; + + if (sym->ts.type == BT_CLASS) + { + /* Initialize _vptr to declared type. */ + gfc_symbol *vtab = gfc_find_derived_vtab (sym->ts.u.derived); + tree rhs; + e = gfc_lval_expr_from_sym (sym); + gfc_add_vptr_component (e); + gfc_init_se (&se, NULL); + se.want_pointer = 1; + gfc_conv_expr (&se, e); + gfc_free_expr (e); + rhs = gfc_build_addr_expr (TREE_TYPE (se.expr), + gfc_get_symbol_decl (vtab)); + gfc_add_modify (&init, se.expr, rhs); + } + gfc_add_init_cleanup (block, gfc_finish_block (&init), tmp); } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fbe37bd..4a49afb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-01-05 Janus Weil + + PR fortran/47024 + * gfortran.dg/storage_size_3.f08: New. + 2011-01-04 Jerry DeLisle PR libgfortran/47154 diff --git a/gcc/testsuite/gfortran.dg/storage_size_3.f08 b/gcc/testsuite/gfortran.dg/storage_size_3.f08 new file mode 100644 index 0000000..71f5011 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/storage_size_3.f08 @@ -0,0 +1,12 @@ +! { dg-do run } +! +! PR 47024: [OOP] STORAGE_SIZE (for polymorphic types): Segfault at run time +! +! Contributed by Tobias Burnus + +type t + integer(kind=4) :: a +end type +class(t), allocatable :: y +if (storage_size(y)/=32) call abort() +end -- 2.7.4