public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-11095] Fortran: reject NULL actual argument without explicit interface [PR107576]
Date: Fri, 25 Nov 2022 22:30:20 +0000 (GMT)	[thread overview]
Message-ID: <20221125223020.F38313858035@sourceware.org> (raw)

https://gcc.gnu.org/g:b3b48f883d31910f2672640de2f5ff59e765488c

commit r10-11095-gb3b48f883d31910f2672640de2f5ff59e765488c
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Nov 17 21:36:49 2022 +0100

    Fortran: reject NULL actual argument without explicit interface [PR107576]
    
    gcc/fortran/ChangeLog:
    
            PR fortran/107576
            * interface.c (gfc_procedure_use): Reject NULL as actual argument
            when there is no explicit procedure interface.
    
    gcc/testsuite/ChangeLog:
    
            PR fortran/107576
            * gfortran.dg/null_actual_3.f90: New test.
    
    (cherry picked from commit 820c25c83561085f54268bd536f9d216d03c3e18)

Diff:
---
 gcc/fortran/interface.c                     |  8 ++++++++
 gcc/testsuite/gfortran.dg/null_actual_3.f90 | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c
index a8a88f19908..19ba7fd65dc 100644
--- a/gcc/fortran/interface.c
+++ b/gcc/fortran/interface.c
@@ -3968,6 +3968,14 @@ gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where)
 	      return false;
 	    }
 
+	  if (a->expr && a->expr->expr_type == EXPR_NULL)
+	    {
+	      gfc_error ("Passing intrinsic NULL as actual argument at %L "
+			 "requires an explicit interface", &a->expr->where);
+	      a->expr->error = 1;
+	      return false;
+	    }
+
 	  /* TS 29113, C407b.  */
 	  if (a->expr && a->expr->expr_type == EXPR_VARIABLE
 	      && symbol_rank (a->expr->symtree->n.sym) == -1)
diff --git a/gcc/testsuite/gfortran.dg/null_actual_3.f90 b/gcc/testsuite/gfortran.dg/null_actual_3.f90
new file mode 100644
index 00000000000..ea49f9630c9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/null_actual_3.f90
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! { dg-options "-fallow-argument-mismatch -w" }
+! PR fortran/107576
+! Contributed by G.Steinmetz
+
+program p
+  implicit none
+  interface
+     subroutine r(y)
+       integer, pointer :: y(:)
+     end subroutine r
+  end interface
+  integer, pointer :: z(:) => null()
+  call r(z)
+  call s(z)
+  call r(null(z))
+  call s(null(z)) ! { dg-error "requires an explicit interface" }
+end

                 reply	other threads:[~2022-11-25 22:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221125223020.F38313858035@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).