PR fortran/101329 - ICE: Invalid expression in gfc_element_size
Commit Message
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
Comments
On 17.11.21 22:28, Harald Anlauf via Fortran wrote:
> 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?
OK, and thanks!
Best regards
Thomas
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
@@ -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";
new file mode 100644
@@ -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