public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-10502] Fortran: fix ICE in get_expr_storage_size [PR108421]
@ 2023-02-04 15:43 Harald Anlauf
  0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2023-02-04 15:43 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2235737a967c9eeabe7b02ffb014d8efef3276af

commit r11-10502-g2235737a967c9eeabe7b02ffb014d8efef3276af
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.c (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.
    
    (cherry picked from commit a75760374ee54768e5fd6a27080698bfbbd041ab)

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

diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index bcc835513d4..efb1257fac2 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -2811,7 +2811,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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-04 15:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-04 15:43 [gcc r11-10502] Fortran: fix ICE in get_expr_storage_size [PR108421] Harald Anlauf

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).