]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: reject invalid CHARACTER length of derived type components [PR96024]
authorHarald Anlauf <anlauf@gmx.de>
Tue, 21 Feb 2023 21:06:33 +0000 (22:06 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sun, 5 Mar 2023 19:36:18 +0000 (20:36 +0100)
gcc/fortran/ChangeLog:

PR fortran/96024
* resolve.c (resolve_component): The type of a CHARACTER length
expression must be INTEGER.

gcc/testsuite/ChangeLog:

PR fortran/96024
* gfortran.dg/pr96024.f90: New test.

(cherry picked from commit 31303c9b5bab200754cdb7ef8cd91ae4918f3018)

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

index 3163f63c996ea44231e9594e1e21e3e7984a9348..288970deca08f0a64164994ac5eb0880994ad7d1 100644 (file)
@@ -14643,6 +14643,19 @@ resolve_component (gfc_component *c, gfc_symbol *sym)
                     c->ts.u.cl->length ? &c->ts.u.cl->length->where : &c->loc);
          return false;
        }
+
+     if (c->ts.u.cl->length && c->ts.u.cl->length->ts.type != BT_INTEGER)
+       {
+        if (!c->ts.u.cl->length->error)
+          {
+            gfc_error ("Character length expression of component %qs at %L "
+                       "must be of INTEGER type, found %s",
+                       c->name, &c->ts.u.cl->length->where,
+                       gfc_basic_typename (c->ts.u.cl->length->ts.type));
+            c->ts.u.cl->length->error = 1;
+          }
+        return false;
+       }
     }
 
   if (c->ts.type == BT_CHARACTER && c->ts.deferred
diff --git a/gcc/testsuite/gfortran.dg/pr96024.f90 b/gcc/testsuite/gfortran.dg/pr96024.f90
new file mode 100644 (file)
index 0000000..2c914a9
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/96024 - ICE in mio_name_expr_t
+! Contributed by G.Steinmetz
+
+module m
+  implicit none
+  type t
+     character(char(1)) :: a ! { dg-error "must be of INTEGER type" }
+  end type
+  type(t) :: z = t('a')
+end