2020-8-21 Steve Kargl <sgk@troutmask.apl.washington.edu>
authorSteve Kargl <sgk@troutmask.apl.washington.edu>
Sun, 30 Aug 2020 17:48:12 +0000 (17:48 +0000)
committerJosé Rui Faustino de Sousa <jrfsousa@gmail.com>
Sun, 30 Aug 2020 17:49:25 +0000 (17:49 +0000)
gcc/fortran/ChangeLog:

PR fortran/95352
* simplify.c (simplify_bound_dim): Add check for NULL pointer
before trying to access structure member.

    José Rui Faustino de Sousa  <jrfsousa@gmail.com>

gcc/testsuite/ChangeLog:

* gfortran.dg/PR95352.f90: New test.

gcc/fortran/simplify.c
gcc/testsuite/gfortran.dg/PR95352.f90 [new file with mode: 0644]

index 8e0d2f97a60128c5313b7d5dbe9a079a9ced7a9c..bfd410cf31d75c7a65ec8264e4984d4c218b55b8 100644 (file)
@@ -4080,7 +4080,7 @@ simplify_bound_dim (gfc_expr *array, gfc_expr *kind, int d, int upper,
       || (coarray && d == as->rank + as->corank
          && (!upper || flag_coarray == GFC_FCOARRAY_SINGLE)))
     {
-      if (as->lower[d-1]->expr_type == EXPR_CONSTANT)
+      if (as->lower[d-1] && as->lower[d-1]->expr_type == EXPR_CONSTANT)
        {
          gfc_free_expr (result);
          return gfc_copy_expr (as->lower[d-1]);
diff --git a/gcc/testsuite/gfortran.dg/PR95352.f90 b/gcc/testsuite/gfortran.dg/PR95352.f90
new file mode 100644 (file)
index 0000000..20c8167
--- /dev/null
@@ -0,0 +1,27 @@
+! { dg-do compile }
+!
+! Test the fix for PR95352
+! 
+  
+module ice6_m
+
+  implicit none
+
+contains
+
+  function ice6_s(a) result(ierr)
+    integer, intent(in) :: a(..)
+
+    integer :: ierr
+
+    integer :: lb
+
+    select rank(a)
+    rank(*)
+      lb = lbound(a, dim=1)
+      if(lbound(a, dim=1)/=lb) ierr = -1
+    end select
+    return
+  end function ice6_s
+  
+end module ice6_m