aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2021-11-17 22:21:24 +0100
committerHarald Anlauf <anlauf@gmx.de>2021-11-18 19:35:43 +0100
commit3535be6c6f440909798d1c78e862a657f7adaf63 (patch)
tree8d841eccce5e8db619325ae471c1f20bf0b3a5f6
parent22c242342e38ebffa6bbf7e86e7a1e4abdf0d686 (diff)
downloadgcc-3535be6c6f440909798d1c78e862a657f7adaf63.zip
gcc-3535be6c6f440909798d1c78e862a657f7adaf63.tar.gz
gcc-3535be6c6f440909798d1c78e862a657f7adaf63.tar.bz2
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>
-rw-r--r--gcc/fortran/check.c6
-rw-r--r--gcc/testsuite/gfortran.dg/pr101329.f9013
2 files changed, 19 insertions, 0 deletions
diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index ffa07b5..5a5aca1 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 0000000..b82210d
--- /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