From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fortran: reject procedures and procedure pointers as output item [PR107074]
Date: Tue, 4 Oct 2022 21:27:11 +0200 [thread overview]
Message-ID: <trinity-6d934a50-8304-4704-bce4-36a2afbc687e-1664911631690@3c-app-gmx-bs14> (raw)
[-- Attachment #1: Type: text/plain, Size: 453 bytes --]
Dear all,
when looking at output item lists we didn't catch procedures
and procedure pointers and ran into a gfc_internal_error().
Such items are not allowed by the Fortran standard, e.g. for
procedure pointers there is
C1233 (R1217) An expression that is an output-item shall not
have a value that is a procedure pointer.
Attached patch generates an error instead.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr107074.diff --]
[-- Type: text/x-patch, Size: 2102 bytes --]
From 3b15fe83830c1e75339114e0241e9d2158393017 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 4 Oct 2022 21:19:21 +0200
Subject: [PATCH] Fortran: reject procedures and procedure pointers as output
item [PR107074]
gcc/fortran/ChangeLog:
PR fortran/107074
* trans-io.cc (transfer_expr): A procedure or a procedure pointer
cannot be output items.
gcc/testsuite/ChangeLog:
PR fortran/107074
* gfortran.dg/pr107074.f90: New test.
---
gcc/fortran/trans-io.cc | 14 ++++++++++++++
gcc/testsuite/gfortran.dg/pr107074.f90 | 11 +++++++++++
2 files changed, 25 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/pr107074.f90
diff --git a/gcc/fortran/trans-io.cc b/gcc/fortran/trans-io.cc
index 9f86815388c..c4e1537eed6 100644
--- a/gcc/fortran/trans-io.cc
+++ b/gcc/fortran/trans-io.cc
@@ -2430,6 +2430,20 @@ transfer_expr (gfc_se * se, gfc_typespec * ts, tree addr_expr,
break;
+ case BT_PROCEDURE:
+ if (code->expr1
+ && code->expr1->symtree
+ && code->expr1->symtree->n.sym)
+ {
+ if (code->expr1->symtree->n.sym->attr.proc_pointer)
+ gfc_error ("Procedure pointer at %C cannot be an output item");
+ else
+ gfc_error ("Procedure at %C cannot be an output item");
+ return;
+ }
+ /* If a PROCEDURE item gets through to here, fall through and ICE. */
+ gcc_fallthrough ();
+
case_bt_struct:
case BT_CLASS:
if (gfc_bt_struct (ts->type) || ts->type == BT_CLASS)
diff --git a/gcc/testsuite/gfortran.dg/pr107074.f90 b/gcc/testsuite/gfortran.dg/pr107074.f90
new file mode 100644
index 00000000000..a09088c2e9d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr107074.f90
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR fortran/107074 - ICE: Bad IO basetype (8)
+! Contributed by G.Steinmetz
+
+program p
+ implicit none
+ integer, external :: a
+ procedure(real), pointer :: b
+ print *, merge (a, a, .true.) ! { dg-error "Procedure" }
+ print *, merge (b, b, .true.) ! { dg-error "Procedure pointer" }
+end
--
2.35.3
next reply other threads:[~2022-10-04 19:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-04 19:27 Harald Anlauf [this message]
2022-10-05 10:34 ` Mikael Morin
2022-10-05 20:40 ` [PATCH, v2] Fortran: reject procedures and procedure pointers as IO element [PR107074] Harald Anlauf
2022-10-06 8:37 ` Mikael Morin
2022-10-06 20:32 ` Mikael Morin
2022-10-06 21:07 ` Aw: " Harald Anlauf
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=trinity-6d934a50-8304-4704-bce4-36a2afbc687e-1664911631690@3c-app-gmx-bs14 \
--to=anlauf@gmx.de \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@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).