re PR fortran/82814 (ICE from submodule character function)
authorPaul Thomas <pault@gcc.gnu.org>
Thu, 23 Nov 2017 09:52:04 +0000 (09:52 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Thu, 23 Nov 2017 09:52:04 +0000 (09:52 +0000)
2017-11-23  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/82814
* trans-types.c (gfc_sym_type): If a character function result
is missing the charlen backend_decl, use the one from the name-
space procedure symbol, if present.

2017-11-23  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/82814
* gfortran.dg/submodule_31.f08: New test.

From-SVN: r255094

gcc/fortran/ChangeLog
gcc/fortran/trans-types.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/submodule_31.f08 [new file with mode: 0644]

index cf1b320a73479e751703794c3408db4b78981db9..036bf7b2994838e52e32be33dab5f0c2ebbba597 100644 (file)
@@ -1,3 +1,10 @@
+2017-11-23  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/82814
+       * trans-types.c (gfc_sym_type): If a character function result
+       is missing the charlen backend_decl, use the one from the name-
+       space procedure symbol, if present.
+
 2017-11-22  David Malcolm  <dmalcolm@redhat.com>
 
        PR c++/62170
index b4ddfdb37cf384783ff369157ea6be11843b5f65..6868329575b8e1818a53358e5e31e0b3843e2774 100644 (file)
@@ -2201,6 +2201,12 @@ gfc_sym_type (gfc_symbol * sym)
   if (sym->backend_decl && !sym->attr.function)
     return TREE_TYPE (sym->backend_decl);
 
+  if (sym->attr.result
+      && sym->ts.type == BT_CHARACTER
+      && sym->ts.u.cl->backend_decl == NULL_TREE
+      && sym->ns->proc_name->ts.u.cl->backend_decl != NULL_TREE)
+    sym->ts.u.cl->backend_decl = sym->ns->proc_name->ts.u.cl->backend_decl;
+
   if (sym->ts.type == BT_CHARACTER
       && ((sym->attr.function && sym->attr.is_bind_c)
          || (sym->attr.result
index ff35bcaf32f77224746e6e134f24267a36c5bcc2..58b9276c5c04c2e92fabac2d254c35f29279f710 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-23  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/82814
+       * gfortran.dg/submodule_31.f08: New test.
+
 2017-11-23  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/23094
diff --git a/gcc/testsuite/gfortran.dg/submodule_31.f08 b/gcc/testsuite/gfortran.dg/submodule_31.f08
new file mode 100644 (file)
index 0000000..72594d0
--- /dev/null
@@ -0,0 +1,54 @@
+! { dg-do run }
+!
+! Test the fix for PR82814 in which an ICE occurred for the submodule allocation.
+!
+! Contributed by "Werner Blokbuster"  <werner.blokbuster@gmail.com>
+!
+module u
+
+    implicit none
+
+    interface unique
+        module function uniq_char(input) result(uniq)
+            character(*), intent(in) :: input(:)
+            character(size(input)), allocatable :: uniq(:)
+        end function uniq_char
+    end interface unique
+
+contains
+
+    module function uniq2(input) result(uniq)
+        character(*), intent(in) :: input(:)
+        character(size(input)), allocatable :: uniq(:)
+            allocate(uniq(1))
+            uniq = 'A'
+    end function uniq2
+
+end module u
+
+
+submodule (u) z
+
+    implicit none
+
+contains
+
+    module function uniq_char(input) result(uniq)
+        character(*), intent(in) :: input(:)
+        character(size(input)), allocatable :: uniq(:)
+            allocate(uniq(1)) ! This used to ICE
+            uniq = 'A'
+    end function uniq_char
+
+end submodule z
+
+
+program test_uniq
+    use u
+    implicit none
+    character(1), dimension(4) :: chr = ['1','2','1','2']
+
+    write(*,*) unique(chr)
+    write(*,*) uniq2(chr)
+
+end program test_uniq