diff options
author | Harald Anlauf <anlauf@gmx.de> | 2021-09-09 21:34:01 +0200 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2021-09-09 21:34:01 +0200 |
commit | 5fe0865ab788bdc387b284a3ad57e5a95a767b18 (patch) | |
tree | 8f852312b8b5c3042d89dbf8c7ecee5f2d838b70 | |
parent | de515ce0b209cc7e5a780d9846e5154d380a763e (diff) | |
download | gcc-5fe0865ab788bdc387b284a3ad57e5a95a767b18.zip gcc-5fe0865ab788bdc387b284a3ad57e5a95a767b18.tar.gz gcc-5fe0865ab788bdc387b284a3ad57e5a95a767b18.tar.bz2 |
Fortran - out of bounds in array constructor with implied do loop
gcc/fortran/ChangeLog:
PR fortran/98490
* trans-expr.c (gfc_conv_substring): Do not generate substring
bounds check for implied do loop index variable before it actually
becomes defined.
gcc/testsuite/ChangeLog:
PR fortran/98490
* gfortran.dg/bounds_check_23.f90: New test.
-rw-r--r-- | gcc/fortran/trans-expr.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/gfortran.dg/bounds_check_23.f90 | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index c4291cc..18d6651 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -2630,7 +2630,9 @@ gfc_conv_substring (gfc_se * se, gfc_ref * ref, int kind, if (!CONSTANT_CLASS_P (tmp) && !DECL_P (tmp)) end.expr = gfc_evaluate_now (end.expr, &se->pre); - if (gfc_option.rtcheck & GFC_RTCHECK_BOUNDS) + if ((gfc_option.rtcheck & GFC_RTCHECK_BOUNDS) + && (ref->u.ss.start->symtree + && !ref->u.ss.start->symtree->n.sym->attr.implied_index)) { tree nonempty = fold_build2_loc (input_location, LE_EXPR, logical_type_node, start.expr, diff --git a/gcc/testsuite/gfortran.dg/bounds_check_23.f90 b/gcc/testsuite/gfortran.dg/bounds_check_23.f90 new file mode 100644 index 0000000..8de90c7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bounds_check_23.f90 @@ -0,0 +1,18 @@ +! { dg-do run } +! { dg-options "-fcheck=bounds -fdump-tree-original" } +! PR fortran/98490 - out of bounds in array constructor with implied do loop + +program test + implicit none + call sub('Lorem ipsum') +contains + subroutine sub( text ) + character(len=*), intent(in) :: text + character(len=1), allocatable :: c(:) + integer :: i + c = [ ( text(i:i), i = 1, len(text) ) ] + if (c(1) /= 'L') stop 1 + end subroutine sub +end program test + +! { dg-final { scan-tree-dump-times "Substring out of bounds:" 2 "original" } } |