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 r13-5232] Fortran: fix ICE in get_expr_storage_size [PR108421]
Date: Tue, 17 Jan 2023 19:39:03 +0000 (GMT)	[thread overview]
Message-ID: <20230117193903.18D523858D28@sourceware.org> (raw)

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

commit r13-5232-ga75760374ee54768e5fd6a27080698bfbbd041ab
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Mon Jan 16 21:30:56 2023 +0100

    Fortran: fix ICE in get_expr_storage_size [PR108421]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/108421
            * interface.cc (get_expr_storage_size): Check that we actually have
            an integer value before trying to extract it with mpz_get_si.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/108421
            * gfortran.dg/pr108421.f90: New test.

Diff:
---
 gcc/fortran/interface.cc               |  3 ++-
 gcc/testsuite/gfortran.dg/pr108421.f90 | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index c4f7faaf597..9593fa83c45 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -2858,7 +2858,8 @@ get_expr_storage_size (gfc_expr *e)
   if (e->ts.type == BT_CHARACTER)
     {
       if (e->ts.u.cl && e->ts.u.cl->length
-          && e->ts.u.cl->length->expr_type == EXPR_CONSTANT)
+	  && e->ts.u.cl->length->expr_type == EXPR_CONSTANT
+	  && e->ts.u.cl->length->ts.type == BT_INTEGER)
 	strlen = mpz_get_si (e->ts.u.cl->length->value.integer);
       else if (e->expr_type == EXPR_CONSTANT
 	       && (e->ts.u.cl == NULL || e->ts.u.cl->length == NULL))
diff --git a/gcc/testsuite/gfortran.dg/pr108421.f90 b/gcc/testsuite/gfortran.dg/pr108421.f90
new file mode 100644
index 00000000000..89439bc7eec
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr108421.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/108421
+! Contributed by G.Steinmetz
+
+program p
+  character(real(3)) :: c ! { dg-error "must be of INTEGER type" }
+  call s(c)
+end
+subroutine s(x)
+  character(*) :: x
+end

                 reply	other threads:[~2023-01-17 19:39 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=20230117193903.18D523858D28@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).