2018-11-24 Paul Thomas <pault@gcc.gnu.org>
authorPaul Thomas <pault@gcc.gnu.org>
Sat, 24 Nov 2018 09:07:23 +0000 (09:07 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sat, 24 Nov 2018 09:07:23 +0000 (09:07 +0000)
PR fortran/888143
* resolve.c (resolve_variable): Check for associate names with
NULL target.

2018-11-24  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/888143
* gfortran.dg/associate_46.f90: New test.

From-SVN: r266427

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

index 6f2947249bc043fa8a2cd74698f1dc037d68f1f4..58ca2635eaf5557f998194d81958d0c5ba25ef88 100644 (file)
@@ -1,3 +1,9 @@
+2018-11-24  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/888143
+       * resolve.c (resolve_variable): Check for associate names with
+       NULL target.
+
 2018-11-23  Jakub Jelinek  <jakub@redhat.com>
 
        * lang.opt (fpad-source): New option.
index df7c6cb13ac78a7afedb6399d2bc9ae71d9623d0..b2090218d48637d6c27196d8d0fd46bcc639bd80 100644 (file)
@@ -5410,7 +5410,7 @@ resolve_variable (gfc_expr *e)
      the ts' type of the component refs is still array valued, which
      can't be translated that way.  */
   if (sym->assoc && e->rank == 0 && e->ref && sym->ts.type == BT_CLASS
-      && sym->assoc->target->ts.type == BT_CLASS
+      && sym->assoc->target && sym->assoc->target->ts.type == BT_CLASS
       && CLASS_DATA (sym->assoc->target)->as)
     {
       gfc_ref *ref = e->ref;
index 587526e7443bff9002661773767aba7ae1e4874a..de3196e59c34aaf3dbab95f6aebee0d80925c4f6 100644 (file)
@@ -1,3 +1,8 @@
+2018-11-24  Paul Thomas  <pault@gcc.gnu.org>
+
+       PR fortran/888143
+       * gfortran.dg/associate_46.f90: New test.
+
 2018-11-23  Jeff Law  <law@redhat.com>
 
        PR rtl-optimization/84768
        Likewise.
        * gcc.target/s390/global-array-even-element.c: Likewise.
 
-2018-11-14  Wilco Dijkstra  <wdijkstr@arm.com>  
+2018-11-14  Wilco Dijkstra  <wdijkstr@arm.com>
            Jackson Woodruff  <jackson.woodruff@arm.com>
 
        PR 71026/tree-optimization
        PR rtl-optimization/87817
        * gcc.target/i386/bmi2-bzhi-3.c (main): Add a couple of new tests.
 
-2018-11-14  Wilco Dijkstra  <wdijkstr@arm.com>  
+2018-11-14  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * gcc.target/aarch64/pr62178.c: Relax scan-assembler checks.
 
diff --git a/gcc/testsuite/gfortran.dg/associate_46.f90 b/gcc/testsuite/gfortran.dg/associate_46.f90
new file mode 100644 (file)
index 0000000..69cc189
--- /dev/null
@@ -0,0 +1,37 @@
+! { dg-do run }
+!
+! Check the fix for PR88143, in which the associate name caused
+! a segfault in resolve.c. Make sure that the associate construct
+! does its job correctly, as well as compiles.
+!
+! Contributed by Andrew Wood  <andrew@fluidgravity.co.uk>
+!
+MODULE m
+   IMPLICIT NONE
+   TYPE t
+      INTEGER, DIMENSION(:), ALLOCATABLE :: i
+   END TYPE
+   CONTAINS
+      SUBROUTINE s(x, idx1, idx2, k)
+         CLASS(*), DIMENSION(:), INTENT(IN), OPTIONAL :: x
+         INTEGER :: idx1, idx2, k
+         SELECT TYPE ( x )
+         CLASS IS ( t )
+            ASSOCIATE ( j => x(idx1)%i )
+               k = j(idx2)
+            END ASSOCIATE
+         END SELECT
+      END
+END
+
+  use m
+  class (t), allocatable :: c(:)
+  integer :: k
+  allocate (c(2))
+  allocate (c(1)%i, source = [3,2,1])
+  allocate (c(2)%i, source = [6,5,4])
+  call s(c, 1, 3, k)
+  if (k .ne. 1) stop 1
+  call s(c, 2, 1, k)
+  if (k .ne. 6) stop 2
+end