]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR fortran/70842 (internal compiler error with character members within...
authorAndre Vehreschild <vehre@gcc.gnu.org>
Fri, 22 Jul 2016 15:01:48 +0000 (17:01 +0200)
committerAndre Vehreschild <vehre@gcc.gnu.org>
Fri, 22 Jul 2016 15:01:48 +0000 (17:01 +0200)
gcc/testsuite/ChangeLog:

2016-07-22  Andre Vehreschild  <vehre@gcc.gnu.org>

Backport from trunk:
PR fortran/70842
* gfortran.dg/select_type_35.f03: New test.

gcc/fortran/ChangeLog:

2016-07-22  Andre Vehreschild  <vehre@gcc.gnu.org>

Backport from trunk:
PR fortran/70842
* simplify.c (gfc_simplify_len): Only for unlimited polymorphic
types replace the expression's _data ref with a _len ref.

From-SVN: r238646

gcc/fortran/simplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/select_type_35.f03 [new file with mode: 0644]

index 3106d798b018ce37835577e097cea5d1bfc00fd1..07c22107a33359a89649862d478cf5ed698071f9 100644 (file)
@@ -3692,8 +3692,12 @@ gfc_simplify_len (gfc_expr *e, gfc_expr *kind)
     }
   else if (e->expr_type == EXPR_VARIABLE && e->ts.type == BT_CHARACTER
           && e->symtree->n.sym
+          && e->symtree->n.sym->ts.type != BT_DERIVED
           && e->symtree->n.sym->assoc && e->symtree->n.sym->assoc->target
-          && e->symtree->n.sym->assoc->target->ts.type == BT_DERIVED)
+          && e->symtree->n.sym->assoc->target->ts.type == BT_DERIVED
+          && e->symtree->n.sym->assoc->target->symtree->n.sym
+          && UNLIMITED_POLY (e->symtree->n.sym->assoc->target->symtree->n.sym))
+
     /* The expression in assoc->target points to a ref to the _data component
        of the unlimited polymorphic entity.  To get the _len component the last
        _data ref needs to be stripped and a ref to the _len component added.  */
index c61873a29fd119b376c789c46a43ea0a16a0132d..a334078a4b0bd5414e153b4e85b1312615e01b4a 100644 (file)
@@ -1,3 +1,9 @@
+2016-07-22  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+       Backport from trunk:
+       PR fortran/70842
+       * gfortran.dg/select_type_35.f03: New test.
+
 2016-07-20  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/71909
diff --git a/gcc/testsuite/gfortran.dg/select_type_35.f03 b/gcc/testsuite/gfortran.dg/select_type_35.f03
new file mode 100644 (file)
index 0000000..92d2f27
--- /dev/null
@@ -0,0 +1,41 @@
+! { dg-do run }
+!
+! Contributed by Nathanael Huebbe
+! Check fix for PR/70842
+
+program foo
+
+  TYPE, ABSTRACT :: t_Intermediate
+  END TYPE t_Intermediate
+
+  type, extends(t_Intermediate) :: t_Foo
+    character(:), allocatable :: string
+  end type t_Foo
+
+  class(t_Foo), allocatable :: obj
+
+  allocate(obj)
+  obj%string = "blabarfoo"
+
+  call bar(obj)
+
+  deallocate(obj)
+contains
+  subroutine bar(me)
+    class(t_Intermediate), target :: me
+
+    class(*), pointer :: alias
+
+    select type(me)
+      type is(t_Foo)
+      if (len(me%string) /= 9) call abort()
+    end select
+
+    alias => me
+    select type(alias)
+      type is(t_Foo)
+        if (len(alias%string) /= 9) call abort()
+    end select
+  end subroutine bar
+end program foo
+