From 1b575de225f39e87b1d4b5c8b5e4ca50f9fbecf4 Mon Sep 17 00:00:00 2001 From: tkoenig Date: Fri, 8 Jun 2018 22:04:11 +0000 Subject: [PATCH] 2018-06-08 Thomas Koenig PR fortran/85631 * trans.h (gfc_ss): Add field no_bounds_check. * trans-array.c (gfc_conv_ss_startstride): If flag_realloc_lhs and ss->no_bounds_check is set, do not use runtime checks. * trans-expr.c (gfc_trans_assignment_1): Set lss->no_bounds_check for reallocatable lhs. 2018-06-08 Thomas Koenig PR fortran/85631 * gfortran.dg/bounds_check_20.f90: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@261348 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/fortran/ChangeLog | 11 ++++++++++- gcc/fortran/trans-array.c | 4 ++-- gcc/fortran/trans-expr.c | 15 +++++++++------ gcc/fortran/trans.h | 1 + gcc/testsuite/ChangeLog | 7 ++++++- gcc/testsuite/gfortran.dg/bounds_check_20.f90 | 24 ++++++++++++++++++++++++ 6 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/bounds_check_20.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index dffc7f46b99..dbda6ef58d6 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,6 +1,15 @@ +2018-06-08 Thomas Koenig + + PR fortran/85631 + * trans.h (gfc_ss): Add field no_bounds_check. + * trans-array.c (gfc_conv_ss_startstride): If flag_realloc_lhs and + ss->no_bounds_check is set, do not use runtime checks. + * trans-expr.c (gfc_trans_assignment_1): Set lss->no_bounds_check + for reallocatable lhs. + 2018-06-08 Steven G. Kargl - PR fortran/86059 + PR fortran/86059 * array.c (match_array_cons_element): NULL() cannot be in an array constructor. diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c index 7e6cea15c6a..97c47252435 100644 --- a/gcc/fortran/trans-array.c +++ b/gcc/fortran/trans-array.c @@ -4304,7 +4304,7 @@ done: } } - /* The rest is just runtime bound checking. */ + /* The rest is just runtime bounds checking. */ if (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS) { stmtblock_t block; @@ -4334,7 +4334,7 @@ done: continue; /* Catch allocatable lhs in f2003. */ - if (flag_realloc_lhs && ss->is_alloc_lhs) + if (flag_realloc_lhs && ss->no_bounds_check) continue; expr = ss_info->expr; diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 8bf550445cc..f85595177c6 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -9982,12 +9982,15 @@ gfc_trans_assignment_1 (gfc_expr * expr1, gfc_expr * expr2, bool init_flag, /* Walk the lhs. */ lss = gfc_walk_expr (expr1); - if (gfc_is_reallocatable_lhs (expr1) - && !(expr2->expr_type == EXPR_FUNCTION - && expr2->value.function.isym != NULL - && !(expr2->value.function.isym->elemental - || expr2->value.function.isym->conversion))) - lss->is_alloc_lhs = 1; + if (gfc_is_reallocatable_lhs (expr1)) + { + lss->no_bounds_check = 1; + if (!(expr2->expr_type == EXPR_FUNCTION + && expr2->value.function.isym != NULL + && !(expr2->value.function.isym->elemental + || expr2->value.function.isym->conversion))) + lss->is_alloc_lhs = 1; + } rss = NULL; diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index 049fcd6cd49..1813882fe36 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -330,6 +330,7 @@ typedef struct gfc_ss struct gfc_loopinfo *loop; unsigned is_alloc_lhs:1; + unsigned no_bounds_check:1; } gfc_ss; #define gfc_get_ss() XCNEW (gfc_ss) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 20ac7c89c96..8b9b37f1970 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-08 Thomas Koenig + + PR fortran/85631 + * gfortran.dg/bounds_check_20.f90: New test. + 2018-06-08 Carl Love * gcc.target/powerpc/p8vector-builtin-3.c: Add vec_pack test. Update @@ -16,7 +21,7 @@ 2018-06-08 Steven G. Kargl - PR fortran/86059 + PR fortran/86059 * gfortran.dg/associate_30.f90: Remove code tested ... * gfortran.dg/pr67803.f90: Ditto. * gfortran.dg/pr67805.f90: Ditto. diff --git a/gcc/testsuite/gfortran.dg/bounds_check_20.f90 b/gcc/testsuite/gfortran.dg/bounds_check_20.f90 new file mode 100644 index 00000000000..86a6d09aa27 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bounds_check_20.f90 @@ -0,0 +1,24 @@ +! { dg-do run } +! { dg-additional-options "-fcheck=bounds -ffrontend-optimize" } +! PR 85631 - this used to cause a runtime error with bounds checking. +module x +contains + subroutine sub(a, b) + real, dimension(:,:), intent(in) :: a + real, dimension(:,:), intent(out), allocatable :: b + b = transpose(a) + end subroutine sub +end module x + +program main + use x + implicit none + real, dimension(2,2) :: a + real, dimension(:,:), allocatable :: b + data a /-2., 3., -5., 7./ + call sub(a, b) + if (any (b /= reshape([-2., -5., 3., 7.], shape(b)))) stop 1 + b = matmul(transpose(b), a) + if (any (b /= reshape([-11., 15., -25., 34.], shape(b)))) stop 2 +end program + -- 2.11.4.GIT