From 8ceba5980c45a7819186bfd699ba3723b9f8b6a0 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Wed, 19 Jul 2023 15:02:32 -0700 Subject: [PATCH] [flang] Ensure that NULL(without MOLD=) not passed to dummy argument with assumed type parameters A dummy argument with an assumed (*) character length or derived type parameter value specification needs to be associated with an actual argument that can supply a value for it, so make sure that a NULL without a MOLD= is not being passed. Differential Revision: https://reviews.llvm.org/D155971 --- flang/lib/Semantics/check-call.cpp | 19 +++++++++++++++++-- flang/test/Semantics/null01.f90 | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp index 3c7b18e..af5a6e9 100644 --- a/flang/lib/Semantics/check-call.cpp +++ b/flang/lib/Semantics/check-call.cpp @@ -909,13 +909,28 @@ static void CheckExplicitInterfaceArg(evaluate::ActualArgument &arg, // ok } else if (object.type.type().IsTypelessIntrinsicArgument() && evaluate::IsNullObjectPointer(*expr)) { - // ok, ASSOCIATED(NULL()) + // ok, ASSOCIATED(NULL(without MOLD=)) } else if ((object.attrs.test(characteristics::DummyDataObject:: Attr::Pointer) || object.attrs.test(characteristics:: DummyDataObject::Attr::Optional)) && evaluate::IsNullObjectPointer(*expr)) { - // ok, FOO(NULL()) + // FOO(NULL(without MOLD=)) + if (object.type.type().IsAssumedLengthCharacter()) { + messages.Say( + "Actual argument associated with %s is a NULL() pointer without a MOLD= to provide a character length"_err_en_US, + dummyName); + } else if (const DerivedTypeSpec * + derived{GetDerivedTypeSpec(object.type.type())}) { + for (const auto &[pName, pValue] : derived->parameters()) { + if (pValue.isAssumed()) { + messages.Say( + "Actual argument associated with %s is a NULL() pointer without a MOLD= to provide a value for the assumed type parameter '%s'"_err_en_US, + dummyName, pName.ToString()); + break; + } + } + } } else if (object.attrs.test(characteristics::DummyDataObject:: Attr::Allocatable) && evaluate::IsNullPointer(*expr)) { diff --git a/flang/test/Semantics/null01.f90 b/flang/test/Semantics/null01.f90 index e2e16fa..c567010 100644 --- a/flang/test/Semantics/null01.f90 +++ b/flang/test/Semantics/null01.f90 @@ -110,3 +110,22 @@ subroutine test if (null(lp)) then end if end subroutine test + +module m + type :: pdt(n) + integer, len :: n + end type + contains + subroutine s1(x) + character(*), pointer, intent(in) :: x + end + subroutine s2(x) + type(pdt(*)), pointer, intent(in) :: x + end + subroutine test + !ERROR: Actual argument associated with dummy argument 'x=' is a NULL() pointer without a MOLD= to provide a character length + call s1(null()) + !ERROR: Actual argument associated with dummy argument 'x=' is a NULL() pointer without a MOLD= to provide a value for the assumed type parameter 'n' + call s2(null()) + end +end -- 2.7.4