PR fortran/101329 - ICE: Invalid expression in gfc_element_size

Message ID trinity-f916ff9f-5b36-483e-8afc-c91e8ce0c441-1637184480215@3c-app-gmx-bap70
State New
Headers
Series PR fortran/101329 - ICE: Invalid expression in gfc_element_size |

Commit Message

Harald Anlauf Nov. 17, 2021, 9:28 p.m. UTC
  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

Thomas Koenig Nov. 18, 2021, 10:51 a.m. UTC | #1
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
  

Patch

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