]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: reject NULL actual argument without explicit interface [PR107576]
authorHarald Anlauf <anlauf@gmx.de>
Thu, 17 Nov 2022 20:36:49 +0000 (21:36 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 25 Nov 2022 22:15:17 +0000 (23:15 +0100)
gcc/fortran/ChangeLog:

PR fortran/107576
* interface.cc (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)

gcc/fortran/interface.cc
gcc/testsuite/gfortran.dg/null_actual_3.f90 [new file with mode: 0644]

index 71eec78259bd4feef951dffcffc665a35c8c1301..0acd78d5f2ee7058e1d04fd7ad742c23de6ab5f6 100644 (file)
@@ -4137,6 +4137,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 (file)
index 0000000..ea49f96
--- /dev/null
@@ -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