]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix ICE in get_expr_storage_size [PR108421]
authorHarald Anlauf <anlauf@gmx.de>
Mon, 16 Jan 2023 20:30:56 +0000 (21:30 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sun, 5 Feb 2023 18:52:10 +0000 (19:52 +0100)
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)

gcc/fortran/interface.c
gcc/testsuite/gfortran.dg/pr108421.f90 [new file with mode: 0644]

index 19ba7fd65dce9dd2c86d1d0555e933a0ad567b70..3fff18bd22689e4d74e82137105bf6c53780f3ae 100644 (file)
@@ -2810,7 +2810,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 (file)
index 0000000..89439bc
--- /dev/null
@@ -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