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-3499] Fortran - fix handling of substring start and end indices
Date: Mon, 13 Sep 2021 17:27:06 +0000 (GMT)	[thread overview]
Message-ID: <20210913172706.761F53858C60@sourceware.org> (raw)

https://gcc.gnu.org/g:8d93ba93d3b13ac3d3c34404cad87732c809605b

commit r12-3499-g8d93ba93d3b13ac3d3c34404cad87732c809605b
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Sep 13 19:26:35 2021 +0200

    Fortran - fix handling of substring start and end indices
    
    gcc/fortran/ChangeLog:
    
            PR fortran/85130
            * expr.c (find_substring_ref): Handle given substring start and
            end indices as signed integers, not unsigned.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/85130
            * gfortran.dg/substr_6.f90: Revert commit r8-7574, adding again
            test that was erroneously considered as illegal.

Diff:
---
 gcc/fortran/expr.c                     | 4 ++--
 gcc/testsuite/gfortran.dg/substr_6.f90 | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index dfecc3012e1..604e63e6164 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -1724,8 +1724,8 @@ find_substring_ref (gfc_expr *p, gfc_expr **newp)
   *newp = gfc_copy_expr (p);
   free ((*newp)->value.character.string);
 
-  end = (gfc_charlen_t) mpz_get_ui (p->ref->u.ss.end->value.integer);
-  start = (gfc_charlen_t) mpz_get_ui (p->ref->u.ss.start->value.integer);
+  end = (gfc_charlen_t) mpz_get_si (p->ref->u.ss.end->value.integer);
+  start = (gfc_charlen_t) mpz_get_si (p->ref->u.ss.start->value.integer);
   if (end >= start)
     length = end - start + 1;
   else
diff --git a/gcc/testsuite/gfortran.dg/substr_6.f90 b/gcc/testsuite/gfortran.dg/substr_6.f90
index 0d5e3d75e88..83e788a55a6 100644
--- a/gcc/testsuite/gfortran.dg/substr_6.f90
+++ b/gcc/testsuite/gfortran.dg/substr_6.f90
@@ -6,6 +6,8 @@ CHARACTER(5), parameter :: c0(1) = (/ "123" // ACHAR(0) // "5" /)
 CHARACTER*5 c(1)
 CHARACTER(1), parameter :: c1(5) = (/ "1", "2", "3", ACHAR(0), "5" /)
 
+c = c0(1)(-5:-8)
+if (c(1) /= "     ") STOP 1
 c = (/ c0(1)(1:5) /)
 do i=1,5
    if (c(1)(i:i) /= c1(i)) STOP 2


                 reply	other threads:[~2021-09-13 17:27 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=20210913172706.761F53858C60@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).