Skip to content

Commit b76e08d

Browse files
authored
[flang] Accept NULL() actual for optional allocatable dummy argument (#66251)
A NULL() pointer is an acceptable actual argument for association with an (absent) optional allocatable dummy argument. Semantics was unconditionally emitting an error that the actual argument is not allocatable.
1 parent e52c558 commit b76e08d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,11 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
657657

658658
// 15.5.2.6 -- dummy is ALLOCATABLE
659659
bool actualIsAllocatable{evaluate::IsAllocatableDesignator(actual)};
660+
bool dummyIsOptional{
661+
dummy.attrs.test(characteristics::DummyDataObject::Attr::Optional)};
662+
bool actualIsNull{evaluate::IsNullPointer(actual)};
660663
if (dummyIsAllocatable) {
661-
if (!actualIsAllocatable) {
664+
if (!actualIsAllocatable && !(actualIsNull && dummyIsOptional)) {
662665
messages.Say(
663666
"ALLOCATABLE %s must be associated with an ALLOCATABLE actual argument"_err_en_US,
664667
dummyName);
@@ -788,9 +791,6 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
788791
}
789792

790793
// NULL(MOLD=) checking for non-intrinsic procedures
791-
bool dummyIsOptional{
792-
dummy.attrs.test(characteristics::DummyDataObject::Attr::Optional)};
793-
bool actualIsNull{evaluate::IsNullPointer(actual)};
794794
if (!intrinsic && !dummyIsPointer && !dummyIsOptional && actualIsNull) {
795795
messages.Say(
796796
"Actual argument associated with %s may not be null pointer %s"_err_en_US,

flang/test/Semantics/null01.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ subroutine canbenull(x, y)
1212
integer, intent(in), optional :: x
1313
real, intent(in), pointer :: y
1414
end
15+
subroutine optionalAllocatable(x)
16+
integer, intent(in), allocatable, optional :: x
17+
end
1518
function f0()
1619
real :: f0
1720
end function
@@ -95,6 +98,7 @@ function f3()
9598
dt4x = dt4(null(dt2x%pps0))
9699
call canbenull(null(), null()) ! fine
97100
call canbenull(null(mold=ip0), null(mold=rp0)) ! fine
101+
call optionalAllocatable(null(mold=ip0)) ! fine
98102
!ERROR: Null pointer argument requires an explicit interface
99103
call implicit(null())
100104
!ERROR: Null pointer argument requires an explicit interface

0 commit comments

Comments
 (0)