re PR fortran/62044 (ICE in USE statement with RENAME for extended derived type)
authorPaul Thomas <pault@gcc.gnu.org>
Mon, 26 Jan 2015 21:58:42 +0000 (21:58 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Mon, 26 Jan 2015 21:58:42 +0000 (21:58 +0000)
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

gcc/fortran/ChangeLog
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/allocate_with_mold_1.f90 [new file with mode: 0644]

index d73bab2feeacf98d62eb7949b8e39b7b169a8863..6a9b71da6718ae56a51c32aa352a93b701972889 100644 (file)
@@ -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
index a9645a0a2143249180ed97a6f9f35923851c8a38..3fe09f6252d34c6a66b8b14d68d6a258c55b2f26 100644 (file)
@@ -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))
index f81676e35d10c394151301549c8983d0bbc6178c..cf72ea9264864c9c096bd77ad266c1d9065e546b 100644 (file)
@@ -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 (file)
index 0000000..6a3f0ad
--- /dev/null
@@ -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
+