From: Harald Anlauf <anlauf@gmx.de>
To: fortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] PR fortran/101329 - ICE: Invalid expression in gfc_element_size
Date: Wed, 17 Nov 2021 22:28:00 +0100 [thread overview]
Message-ID: <trinity-f916ff9f-5b36-483e-8afc-c91e8ce0c441-1637184480215@3c-app-gmx-bap70> (raw)
[-- Attachment #1: Type: text/plain, Size: 232 bytes --]
Dear Fortranners,
as NULL() is not interoperable, we have to reject it.
Confirmed by NAG. Other compilers show "interesting behavior".
Obvious patch by Steve. Regtested on x86_64-pc-linux-gnu.
OK for mainline?
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-NULL-is-not-interoperable.patch --]
[-- Type: text/x-patch, Size: 1910 bytes --]
From 52a3ee53f0a12e897c4651fa8378e045653b9fd3 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 17 Nov 2021 22:21:24 +0100
Subject: [PATCH] Fortran: NULL() is not interoperable
gcc/fortran/ChangeLog:
PR fortran/101329
* check.c (is_c_interoperable): Reject NULL() as it is not
interoperable.
gcc/testsuite/ChangeLog:
PR fortran/101329
* gfortran.dg/pr101329.f90: New test.
Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
---
gcc/fortran/check.c | 6 ++++++
gcc/testsuite/gfortran.dg/pr101329.f90 | 13 +++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/pr101329.f90
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index ffa07b510cd..5a5aca10ebe 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -5223,6 +5223,12 @@ is_c_interoperable (gfc_expr *expr, const char **msg, bool c_loc, bool c_f_ptr)
{
*msg = NULL;
+ if (expr->expr_type == EXPR_NULL)
+ {
+ *msg = "NULL() is not interoperable";
+ return false;
+ }
+
if (expr->ts.type == BT_CLASS)
{
*msg = "Expression is polymorphic";
diff --git a/gcc/testsuite/gfortran.dg/pr101329.f90 b/gcc/testsuite/gfortran.dg/pr101329.f90
new file mode 100644
index 00000000000..b82210d4e28
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr101329.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! PR fortran/101329 - ICE: Invalid expression in gfc_element_size
+
+program p
+ use iso_c_binding
+ implicit none
+ integer(c_int), pointer :: ip4
+ integer(c_int64_t), pointer :: ip8
+ print *, c_sizeof (c_null_ptr) ! valid
+ print *, c_sizeof (null ()) ! { dg-error "is not interoperable" }
+ print *, c_sizeof (null (ip4)) ! { dg-error "is not interoperable" }
+ print *, c_sizeof (null (ip8)) ! { dg-error "is not interoperable" }
+end
--
2.26.2
next reply other threads:[~2021-11-17 21:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-17 21:28 Harald Anlauf [this message]
2021-11-18 10:51 ` Thomas Koenig
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-f916ff9f-5b36-483e-8afc-c91e8ce0c441-1637184480215@3c-app-gmx-bap70 \
--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).