From cd49b7067893b548a10c99ea0cb6aba2977eef2e Mon Sep 17 00:00:00 2001 From: Steve Kargl Date: Sun, 30 Aug 2020 17:48:12 +0000 Subject: [PATCH] 2020-8-21 Steve Kargl MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 gcc/testsuite/ChangeLog: * gfortran.dg/PR95352.f90: New test. --- gcc/fortran/simplify.c | 2 +- gcc/testsuite/gfortran.dg/PR95352.f90 | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/PR95352.f90 diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 8e0d2f97a60..bfd410cf31d 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -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 index 00000000000..20c81675212 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR95352.f90 @@ -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 -- 2.30.2