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-10398] Fortran: Fix assumed length chars and len inquiry [PR103716]
Date: Fri, 26 Apr 2024 19:16:10 +0000 (GMT)	[thread overview]
Message-ID: <20240426191610.A1CE23858C42@sourceware.org> (raw)

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

commit r12-10398-gb482968801158116dd8ba3b15a4c29143b2a423a
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Tue May 23 06:46:37 2023 +0100

    Fortran: Fix assumed length chars and len inquiry [PR103716]
    
    2023-05-23  Paul Thomas  <pault@gcc.gnu.org>
    
    gcc/fortran
            PR fortran/103716
            * resolve.cc (gfc_resolve_ref): Conversion of array_ref into an
            element should be done for all characters without a len expr,
            not just deferred lens, and for integer expressions.
            * trans-expr.cc (conv_inquiry): For len and kind inquiry refs,
            set the se string_length to NULL_TREE.
    
    gcc/testsuite/
            PR fortran/103716
            * gfortran.dg/pr103716.f90 : New test.
    
    (cherry picked from commit 842a432b02238361ecc601d301ac400a7f30f4fa)

Diff:
---
 gcc/fortran/resolve.cc                 |  4 +++-
 gcc/fortran/trans-expr.cc              |  2 ++
 gcc/testsuite/gfortran.dg/pr103716.f90 | 15 +++++++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 9264322f671..6a7325e15e7 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -5461,7 +5461,9 @@ gfc_resolve_ref (gfc_expr *expr)
 	case REF_INQUIRY:
 	  /* Implement requirement in note 9.7 of F2018 that the result of the
 	     LEN inquiry be a scalar.  */
-	  if (ref->u.i == INQUIRY_LEN && array_ref && expr->ts.deferred)
+	  if (ref->u.i == INQUIRY_LEN && array_ref
+	      && ((expr->ts.type == BT_CHARACTER && !expr->ts.u.cl->length)
+		  || expr->ts.type == BT_INTEGER))
 	    {
 	      array_ref->u.ar.type = AR_ELEMENT;
 	      expr->rank = 0;
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 11ee1931b8e..e78a01003c9 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -2854,11 +2854,13 @@ conv_inquiry (gfc_se * se, gfc_ref * ref, gfc_expr *expr, gfc_typespec *ts)
     case INQUIRY_KIND:
       res = build_int_cst (gfc_typenode_for_spec (&expr->ts),
 			   ts->kind);
+      se->string_length = NULL_TREE;
       break;
 
     case INQUIRY_LEN:
       res = fold_convert (gfc_typenode_for_spec (&expr->ts),
 			  se->string_length);
+      se->string_length = NULL_TREE;
       break;
 
     default:
diff --git a/gcc/testsuite/gfortran.dg/pr103716.f90 b/gcc/testsuite/gfortran.dg/pr103716.f90
new file mode 100644
index 00000000000..4f78900839e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103716.f90
@@ -0,0 +1,15 @@
+! { dg-do compile }
+!
+! The gimplifier used to throw a fit on thes two functions.
+!
+! Contributed by Gerhard Steinmetz  <gscfq@t-online.de>
+!
+function f1(x)
+   character(*) :: x(*)
+   print *, g(x%len)
+end
+
+function f2(x)
+   character(*) :: x(3)
+   print *, g(x%len)
+end

                 reply	other threads:[~2024-04-26 19:16 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=20240426191610.A1CE23858C42@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).