]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/88143 (ICE in resolve_variable at gcc/fortran/resolve.c:5413 since...
authorPaul Thomas <pault@gcc.gnu.org>
Sat, 24 Nov 2018 18:54:52 +0000 (18:54 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Sat, 24 Nov 2018 18:54:52 +0000 (18:54 +0000)
2018-11-24  Paul Thomas  <pault@gcc.gnu.org>

PR fortran/88143
* resolve.c (resolve_variable): Check for associate names with
NULL target.

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

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

From-SVN: r266431

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

index 6c85b63169cb3519db2d7233fb5fd67b4d09e70e..95f097cad1ec0b4ad3cb74c9ea8f21cb1febafde 100644 (file)
@@ -1,3 +1,10 @@
+2018-11-24  Paul Thomas  <pault@gcc.gnu.org>
+
+       Backport from mainline
+       PR fortran/88143
+       * resolve.c (resolve_variable): Check for associate names with
+       NULL target.
+
 2019-11-03  Tobias Burnus  <burnus@net-b.de>
        Thomas Koenig  <tkoenig@gcc.gnu.org>
 
index 483f3b2a7b703dba5e7d5ae421e7f4893896a1d0..06d98da636d505acf5dea9c52d980e7fdc3326d3 100644 (file)
@@ -5132,7 +5132,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 4194ad6185e6e30f35c2df1b0012d031d16344d5..7d3dbd150a502e85bdd6a1c23481b32dd88d5157 100644 (file)
@@ -1,3 +1,9 @@
+2018-11-24  Paul Thomas  <pault@gcc.gnu.org>
+
+       Backport from mainline
+       PR fortran/88143
+       * gfortran.dg/associate_46.f90: New test.
+
 2018-11-22  Eric Botcazou  <ebotcazou@adacore.com>
 
        Backport from mainline
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