]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: NULL() is not interoperable
authorHarald Anlauf <anlauf@gmx.de>
Wed, 17 Nov 2021 21:21:24 +0000 (22:21 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Thu, 18 Nov 2021 18:35:43 +0000 (19:35 +0100)
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
gcc/testsuite/gfortran.dg/pr101329.f90 [new file with mode: 0644]

index ffa07b510cd81946a465b64f3a2dda7bfec4b55a..5a5aca10ebe15e7cb7d660bc5802fe72afbb7406 100644 (file)
@@ -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 (file)
index 0000000..b82210d
--- /dev/null
@@ -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