diff options
author | Harald Anlauf <anlauf@gmx.de> | 2025-03-06 21:45:42 +0100 |
---|---|---|
committer | Harald Anlauf <anlauf@gmx.de> | 2025-03-06 22:41:33 +0100 |
commit | ac8a70db59ac309daf866a65b5785e472e76d406 (patch) | |
tree | afb5bba108f523171e35eafb80a8b2e8a038a0ab /gcc/fortran/trans-expr.cc | |
parent | be0942afb3a7080b7b0420a5369bdcf3dcc74b52 (diff) | |
download | gcc-ac8a70db59ac309daf866a65b5785e472e76d406.zip gcc-ac8a70db59ac309daf866a65b5785e472e76d406.tar.gz gcc-ac8a70db59ac309daf866a65b5785e472e76d406.tar.bz2 |
Fortran: improve checking of substring bounds [PR119118]
After the fix for pr98490 no substring bounds check was generated if the
substring start was not a variable. While the purpose of that fix was to
suppress a premature check before implied-do indices were substituted, this
prevented a check if the substring start was an expression or a constant.
A better solution is to defer the check until implied-do indices have been
substituted in the start and end expressions.
PR fortran/119118
gcc/fortran/ChangeLog:
* dependency.cc (gfc_contains_implied_index_p): Helper function to
determine if an expression has a dependence on an implied-do index.
* dependency.h (gfc_contains_implied_index_p): Add prototype.
* trans-expr.cc (gfc_conv_substring): Adjust logic to not generate
substring bounds checks before implied-do indices have been
substituted.
gcc/testsuite/ChangeLog:
* gfortran.dg/bounds_check_23.f90: Generalize test.
* gfortran.dg/bounds_check_26.f90: New test.
Diffstat (limited to 'gcc/fortran/trans-expr.cc')
-rw-r--r-- | gcc/fortran/trans-expr.cc | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc index fbe7333..d965539 100644 --- a/gcc/fortran/trans-expr.cc +++ b/gcc/fortran/trans-expr.cc @@ -2814,8 +2814,8 @@ gfc_conv_substring (gfc_se * se, gfc_ref * ref, int kind, end.expr = gfc_evaluate_now (end.expr, &se->pre); if ((gfc_option.rtcheck & GFC_RTCHECK_BOUNDS) - && (ref->u.ss.start->symtree - && !ref->u.ss.start->symtree->n.sym->attr.implied_index)) + && !gfc_contains_implied_index_p (ref->u.ss.start) + && !gfc_contains_implied_index_p (ref->u.ss.end)) { tree nonempty = fold_build2_loc (input_location, LE_EXPR, logical_type_node, start.expr, |