* [PATCH] Fortran: reject invalid CHARACTER length of derived type components [PR96024]
@ 2023-02-21 21:18 Harald Anlauf
2023-02-21 22:00 ` Steve Kargl
0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2023-02-21 21:18 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 325 bytes --]
Dear all,
the attached simple patch detects and rejects CHARACTER components
of derived types whose length specification is non-integer.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
This PR is also marked as a 10/11/12/13 regression, so I would
like to backport this as far as it seems reasonable.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr96024.diff --]
[-- Type: text/x-patch, Size: 2038 bytes --]
From 0a392415cb5d5486e3e660880c81d6fdbbb47285 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 21 Feb 2023 22:06:33 +0100
Subject: [PATCH] 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.
---
gcc/fortran/resolve.cc | 13 +++++++++++++
gcc/testsuite/gfortran.dg/pr96024.f90 | 11 +++++++++++
2 files changed, 24 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/pr96024.f90
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
--
2.35.3
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fortran: reject invalid CHARACTER length of derived type components [PR96024]
2023-02-21 21:18 [PATCH] Fortran: reject invalid CHARACTER length of derived type components [PR96024] Harald Anlauf
@ 2023-02-21 22:00 ` Steve Kargl
0 siblings, 0 replies; 2+ messages in thread
From: Steve Kargl @ 2023-02-21 22:00 UTC (permalink / raw)
To: Harald Anlauf via Fortran; +Cc: gcc-patches
On Tue, Feb 21, 2023 at 10:18:58PM +0100, Harald Anlauf via Fortran wrote:
> Dear all,
>
> the attached simple patch detects and rejects CHARACTER components
> of derived types whose length specification is non-integer.
>
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
>
> This PR is also marked as a 10/11/12/13 regression, so I would
> like to backport this as far as it seems reasonable.
>
OK. Backports are fine with me, but give others a
chance to comment.
Thanks for continuing to pursue the backlog of bug reports.
--
Steve
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-21 22:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-21 21:18 [PATCH] Fortran: reject invalid CHARACTER length of derived type components [PR96024] Harald Anlauf
2023-02-21 22:00 ` Steve Kargl
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).