From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id A6BDB3858012; Thu, 18 Nov 2021 18:36:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6BDB3858012 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5384] Fortran: NULL() is not interoperable X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/master X-Git-Oldrev: 22c242342e38ebffa6bbf7e86e7a1e4abdf0d686 X-Git-Newrev: 3535be6c6f440909798d1c78e862a657f7adaf63 Message-Id: <20211118183643.A6BDB3858012@sourceware.org> Date: Thu, 18 Nov 2021 18:36:43 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Nov 2021 18:36:43 -0000 https://gcc.gnu.org/g:3535be6c6f440909798d1c78e862a657f7adaf63 commit r12-5384-g3535be6c6f440909798d1c78e862a657f7adaf63 Author: Harald Anlauf Date: Wed Nov 17 22:21:24 2021 +0100 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 Diff: --- gcc/fortran/check.c | 6 ++++++ gcc/testsuite/gfortran.dg/pr101329.f90 | 13 +++++++++++++ 2 files changed, 19 insertions(+) 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