Skip to content

[flang] Accept NULL() actual for optional allocatable dummy argument #66251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions flang/lib/Semantics/check-call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,11 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,

// 15.5.2.6 -- dummy is ALLOCATABLE
bool actualIsAllocatable{evaluate::IsAllocatableDesignator(actual)};
bool dummyIsOptional{
dummy.attrs.test(characteristics::DummyDataObject::Attr::Optional)};
bool actualIsNull{evaluate::IsNullPointer(actual)};
if (dummyIsAllocatable) {
if (!actualIsAllocatable) {
if (!actualIsAllocatable && !(actualIsNull && dummyIsOptional)) {
messages.Say(
"ALLOCATABLE %s must be associated with an ALLOCATABLE actual argument"_err_en_US,
dummyName);
Expand Down Expand Up @@ -788,9 +791,6 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
}

// NULL(MOLD=) checking for non-intrinsic procedures
bool dummyIsOptional{
dummy.attrs.test(characteristics::DummyDataObject::Attr::Optional)};
bool actualIsNull{evaluate::IsNullPointer(actual)};
if (!intrinsic && !dummyIsPointer && !dummyIsOptional && actualIsNull) {
messages.Say(
"Actual argument associated with %s may not be null pointer %s"_err_en_US,
Expand Down
4 changes: 4 additions & 0 deletions flang/test/Semantics/null01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ subroutine canbenull(x, y)
integer, intent(in), optional :: x
real, intent(in), pointer :: y
end
subroutine optionalAllocatable(x)
integer, intent(in), allocatable, optional :: x
end
function f0()
real :: f0
end function
Expand Down Expand Up @@ -95,6 +98,7 @@ function f3()
dt4x = dt4(null(dt2x%pps0))
call canbenull(null(), null()) ! fine
call canbenull(null(mold=ip0), null(mold=rp0)) ! fine
call optionalAllocatable(null(mold=ip0)) ! fine
!ERROR: Null pointer argument requires an explicit interface
call implicit(null())
!ERROR: Null pointer argument requires an explicit interface
Expand Down