Skip to content

Commit

Permalink
[flang] Ensure that NULL(without MOLD=) not passed to dummy argument …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
klausler committed Jul 21, 2023
1 parent d9d9a2c commit 8ceba59
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
19 changes: 17 additions & 2 deletions flang/lib/Semantics/check-call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
19 changes: 19 additions & 0 deletions flang/test/Semantics/null01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,22 @@ function f3()
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

0 comments on commit 8ceba59

Please sign in to comment.