public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-3273] Fortran - extend set of substring expressions handled in length simplification
Date: Tue, 31 Aug 2021 19:01:30 +0000 (GMT)	[thread overview]
Message-ID: <20210831190130.A136E3858C27@sourceware.org> (raw)

https://gcc.gnu.org/g:e4cb3bb9ac11b4126ffa718287dd509a4b10a658

commit r12-3273-ge4cb3bb9ac11b4126ffa718287dd509a4b10a658
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Aug 31 21:00:53 2021 +0200

    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.

Diff:
---
 gcc/fortran/simplify.c                 | 31 ++-----------------------------
 gcc/testsuite/gfortran.dg/pr100950.f90 | 12 ++++++++++++
 2 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c
index 4cb73e836c7..b46cbfa90ab 100644
--- a/gcc/fortran/simplify.c
+++ b/gcc/fortran/simplify.c
@@ -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;
 
diff --git a/gcc/testsuite/gfortran.dg/pr100950.f90 b/gcc/testsuite/gfortran.dg/pr100950.f90
index cb9d126bc18..a19409c2507 100644
--- a/gcc/testsuite/gfortran.dg/pr100950.f90
+++ b/gcc/testsuite/gfortran.dg/pr100950.f90
@@ -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" } }


                 reply	other threads:[~2021-08-31 19:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210831190130.A136E3858C27@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).