From: Thomas König Date: Sun, 19 Apr 2020 10:56:32 +0000 (+0200) Subject: Fix PR fortran/93500, ICE on invalid. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4dc6437183aec5439b88b076315ad8f31794d24b;p=gcc.git Fix PR fortran/93500, ICE on invalid. Returning &gfc_bad_expr when simplifying bounds after a divisin by zero happened results in the division by zero error actually reaching the user. 2020-04-19 Thomas Koenig PR fortran/93500 * resolve.c (resolve_operator): If both operands are NULL, return false. * simplify.c (simplify_bound): If a division by zero was seen during bound simplification, free the corresponcing expression and return &gfc_bad_expr. 2020-04-19 Thomas Koenig PR fortran/93500 * arith_divide_3.f90: New test. --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 2f99ce24599..336ce49090e 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,12 @@ +2020-04-19 Thomas Koenig + + PR fortran/93500 + * resolve.c (resolve_operator): If both operands are + NULL, return false. + * simplify.c (simplify_bound): If a division by zero + was seen during bound simplification, free the + corresponcing expression and return &gfc_bad_expr. + 2020-04-17 Thomas Koenig PR fortran/94090 diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 2371ab23645..fd3b025a84f 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -3992,6 +3992,9 @@ resolve_operator (gfc_expr *e) op1 = e->value.op.op1; op2 = e->value.op.op2; + if (op1 == NULL && op2 == NULL) + return false; + dual_locus_error = false; /* op1 and op2 cannot both be BOZ. */ diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index d5703e38251..c7a4f77e70b 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4251,7 +4251,11 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) for (j = 0; j < d; j++) gfc_free_expr (bounds[j]); - return bounds[d]; + + if (gfc_seen_div0) + return &gfc_bad_expr; + else + return bounds[d]; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9f8ae6ccccb..e8742902d12 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-04-19 Thomas Koenig + + PR fortran/93500 + * arith_divide_3.f90: New test. + 2020-04-19 Jakub Jelinek PR objc/94637 diff --git a/gcc/testsuite/gfortran.dg/arith_divide_3.f90 b/gcc/testsuite/gfortran.dg/arith_divide_3.f90 new file mode 100644 index 00000000000..95682dfdda7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/arith_divide_3.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! { dg-options "-fcoarray=single" } +! PR 93500 - this used to cause an ICE + +program p + integer :: a(min(2,0)/0) ! { dg-error "Division by zero" } + integer, save :: c[min(2,0)/0,*] ! { dg-error "Division by zero|must have constant shape" } + integer :: b = lbound(a) ! { dg-error "must be an array" } + print *,lcobound(c) +end program p + +subroutine s + integer :: a(min(2,0)/0) ! { dg-error "Division by zero" } + integer, save :: c[min(2,0)/0,*] ! { dg-error "Division by zero" } + integer :: b = lbound(a) + print *,lcobound(c) +end subroutine s