aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaul Thomas <pault@gcc.gnu.org>2015-01-26 21:58:42 +0000
committerPaul Thomas <pault@gcc.gnu.org>2015-01-26 21:58:42 +0000
commit40a778bd519125d4385bc155d9ae6e6e04d703c3 (patch)
treeee654adf268670eddd69d015f6fba4df4f5f882f /gcc
parent1b7706c830cdf535d14d68d4f2e581592fbcdb85 (diff)
downloadgcc-40a778bd519125d4385bc155d9ae6e6e04d703c3.zip
gcc-40a778bd519125d4385bc155d9ae6e6e04d703c3.tar.gz
gcc-40a778bd519125d4385bc155d9ae6e6e04d703c3.tar.bz2
re PR fortran/62044 (ICE in USE statement with RENAME for extended derived type)
2015-01-26 Paul Thomas <pault@gcc.gnu.org> 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 <pault@gcc.gnu.org> PR fortran/62044 * gfortran.dg/allocate_with_mold_1.f90: New test From-SVN: r220140
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/resolve.c9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/allocate_with_mold_1.f9047
4 files changed, 65 insertions, 3 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index d73bab2..6a9b71d 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-26 Paul Thomas <pault@gcc.gnu.org>
+
+ 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 <burnus@net-b.de>
PR fortran/64771
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index a9645a0..3fe09f6 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 f81676e..cf72ea92 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-26 Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/62044
+ * gfortran.dg/allocate_with_mold_1.f90: New test
+
2015-01-26 Jakub Jelinek <jakub@redhat.com>
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 0000000..6a3f0ad
--- /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 <pault@gcc.gnu.org>
+!
+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
+