From: Harald Anlauf Date: Thu, 17 Nov 2022 20:36:49 +0000 (+0100) Subject: Fortran: reject NULL actual argument without explicit interface [PR107576] X-Git-Tag: release-12.2.mpacbti-rel1~252 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a7a103dd46cc079252302be69cfef188caee74d;p=thirdparty%2Fgcc.git Fortran: reject NULL actual argument without explicit interface [PR107576] 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) --- diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index 71eec78259bd..0acd78d5f2ee 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -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 index 000000000000..ea49f9630c96 --- /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