From 40a778bd519125d4385bc155d9ae6e6e04d703c3 Mon Sep 17 00:00:00 2001 From: Paul Thomas Date: Mon, 26 Jan 2015 21:58:42 +0000 Subject: [PATCH] re PR fortran/62044 (ICE in USE statement with RENAME for extended derived type) 2015-01-26 Paul Thomas PR fortran/62044 * resolve.c (resolve_allocate_expr): If the default initializer is NULL, keep the original MOLD expression so that the correct typespec is available. 2015-01-26 Paul Thomas PR fortran/62044 * gfortran.dg/allocate_with_mold_1.f90: New test From-SVN: r220140 --- gcc/fortran/ChangeLog | 7 +++ gcc/fortran/resolve.c | 9 ++-- gcc/testsuite/ChangeLog | 5 ++ .../gfortran.dg/allocate_with_mold_1.f90 | 47 +++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/allocate_with_mold_1.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index d73bab2feea..6a9b71da671 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2015-01-26 Paul Thomas + + PR fortran/62044 + * resolve.c (resolve_allocate_expr): If the default initializer + is NULL, keep the original MOLD expression so that the correct + typespec is available. + 2015-01-26 Tobias Burnus PR fortran/64771 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index a9645a0a214..3fe09f6252d 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -6995,9 +6995,12 @@ resolve_allocate_expr (gfc_expr *e, gfc_code *code) { /* Default initialization via MOLD (non-polymorphic). */ gfc_expr *rhs = gfc_default_initializer (&code->expr3->ts); - gfc_resolve_expr (rhs); - gfc_free_expr (code->expr3); - code->expr3 = rhs; + if (rhs != NULL) + { + gfc_resolve_expr (rhs); + gfc_free_expr (code->expr3); + code->expr3 = rhs; + } } if (e->ts.type == BT_CLASS && !unlimited && !UNLIMITED_POLY (code->expr3)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f81676e35d1..cf72ea92648 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-01-26 Paul Thomas + + PR fortran/62044 + * gfortran.dg/allocate_with_mold_1.f90: New test + 2015-01-26 Jakub Jelinek PR c/64778 diff --git a/gcc/testsuite/gfortran.dg/allocate_with_mold_1.f90 b/gcc/testsuite/gfortran.dg/allocate_with_mold_1.f90 new file mode 100644 index 00000000000..6a3f0adce1f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/allocate_with_mold_1.f90 @@ -0,0 +1,47 @@ +! { dg-do run } +! +! Fixes a bug that emerged from the fix of PR62044 - see the PR. When +! there was no default initializer, code-expr3 was set null and so the +! vpointer was set to the vtable of the declared type, rather than that +! of the MOLD expression. +! +! Contributed by but based on the original PR62044 testcase by +! Paul Thomas +! +module GridImageSilo_Template + implicit none + type, public, abstract :: GridImageSiloTemplate + end type GridImageSiloTemplate +end module GridImageSilo_Template + +module UnstructuredGridImageSilo_Form + use GridImageSilo_Template + implicit none + type, public, extends ( GridImageSiloTemplate ) :: & + UnstructuredGridImageSiloForm + end type UnstructuredGridImageSiloForm +end module UnstructuredGridImageSilo_Form + +module UnstructuredGridImages + use UnstructuredGridImageSilo_Form, & + UnstructuredGridImageForm => UnstructuredGridImageSiloForm +contains + subroutine foo + class (GridImageSiloTemplate), allocatable :: a + type (UnstructuredGridImageForm) :: b + integer :: i = 0 + allocate (a, mold = b) + select type (a) + type is (UnstructuredGridImageForm) + i = 1 + class default + i = 2 + end select + if (i .ne. 1) call abort + end subroutine +end module UnstructuredGridImages + + use UnstructuredGridImages + call foo +end + -- 2.30.2