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-6289] Fortran: reject invalid CHARACTER length of derived type components [PR96024]
Date: Wed, 22 Feb 2023 17:56:16 +0000 (GMT)	[thread overview]
Message-ID: <20230222175616.A74013858C83@sourceware.org> (raw)

https://gcc.gnu.org/g:31303c9b5bab200754cdb7ef8cd91ae4918f3018

commit r13-6289-g31303c9b5bab200754cdb7ef8cd91ae4918f3018
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Tue Feb 21 22:06:33 2023 +0100

    Fortran: reject invalid CHARACTER length of derived type components [PR96024]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/96024
            * resolve.cc (resolve_component): The type of a CHARACTER length
            expression must be INTEGER.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/96024
            * gfortran.dg/pr96024.f90: New test.

Diff:
---
 gcc/fortran/resolve.cc                | 13 +++++++++++++
 gcc/testsuite/gfortran.dg/pr96024.f90 | 11 +++++++++++
 2 files changed, 24 insertions(+)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 427f901a438..2780c82c798 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -14892,6 +14892,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
index 00000000000..2c914a997f2
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr96024.f90
@@ -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

                 reply	other threads:[~2023-02-22 17:56 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=20230222175616.A74013858C83@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).