Fortran - extend set of substring expressions handled in length simplification
gcc/fortran/ChangeLog: PR fortran/100950 * simplify.c (substring_has_constant_len): Minimize checks for substring expressions being allowed. gcc/testsuite/ChangeLog: PR fortran/100950 * gfortran.dg/pr100950.f90: Extend coverage.
This commit is contained in:
parent
ef7becc9c8
commit
e4cb3bb9ac
2 changed files with 14 additions and 29 deletions
|
@ -4533,14 +4533,7 @@ substring_has_constant_len (gfc_expr *e)
|
|||
|| !ref->u.ss.start
|
||||
|| ref->u.ss.start->expr_type != EXPR_CONSTANT
|
||||
|| !ref->u.ss.end
|
||||
|| ref->u.ss.end->expr_type != EXPR_CONSTANT
|
||||
|| !ref->u.ss.length)
|
||||
return false;
|
||||
|
||||
/* For non-deferred strings the given length shall be constant. */
|
||||
if (!e->ts.deferred
|
||||
&& (!ref->u.ss.length->length
|
||||
|| ref->u.ss.length->length->expr_type != EXPR_CONSTANT))
|
||||
|| ref->u.ss.end->expr_type != EXPR_CONSTANT)
|
||||
return false;
|
||||
|
||||
/* Basic checks on substring starting and ending indices. */
|
||||
|
@ -4551,27 +4544,7 @@ substring_has_constant_len (gfc_expr *e)
|
|||
iend = gfc_mpz_get_hwi (ref->u.ss.end->value.integer);
|
||||
|
||||
if (istart <= iend)
|
||||
{
|
||||
if (istart < 1)
|
||||
{
|
||||
gfc_error ("Substring start index (%wd) at %L below 1",
|
||||
istart, &ref->u.ss.start->where);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* For deferred strings use end index as proxy for length. */
|
||||
if (e->ts.deferred)
|
||||
length = iend;
|
||||
else
|
||||
length = gfc_mpz_get_hwi (ref->u.ss.length->length->value.integer);
|
||||
if (iend > length)
|
||||
{
|
||||
gfc_error ("Substring end index (%wd) at %L exceeds string length",
|
||||
iend, &ref->u.ss.end->where);
|
||||
return false;
|
||||
}
|
||||
length = iend - istart + 1;
|
||||
}
|
||||
length = iend - istart + 1;
|
||||
else
|
||||
length = 0;
|
||||
|
||||
|
|
|
@ -46,6 +46,18 @@ program p
|
|||
integer, parameter :: l9 = len (r(1)%u(:)(3:4))
|
||||
if (l9 /= 2) stop 13
|
||||
end block
|
||||
|
||||
call sub (42, "abcde")
|
||||
contains
|
||||
subroutine sub (m, c)
|
||||
integer, intent(in) :: m
|
||||
character(len=*), intent(in) :: c
|
||||
character(len=m) :: p, o(3)
|
||||
integer, parameter :: l10 = len (p(6:7))
|
||||
integer, parameter :: l11 = len (o(:)(6:7))
|
||||
integer, parameter :: l12 = len (c(2:3))
|
||||
if (l10 /= 2 .or. l11 /= 2 .or. l12 /= 2) stop 14
|
||||
end subroutine sub
|
||||
end
|
||||
|
||||
! { dg-final { scan-tree-dump-times "_gfortran_stop_numeric" 2 "original" } }
|
||||
|
|
Loading…
Add table
Reference in a new issue