Skip to content

Commit b8b90c2

Browse files
authored
[flang] Silence bogus error about NULL() actual for assumed-rank dummy (#93225)
A NULL(without MOLD=) actual argument can be associated with an OPTIONAL assumed-rank non-allocatable non-pointer dummy argument; it simply signifies that the corresponding actual argument is absent, and thus none of its dynamic attributes, including rank, are meaningful.
1 parent 9e81466 commit b8b90c2

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,20 +1129,20 @@ static void CheckExplicitInterfaceArg(evaluate::ActualArgument &arg,
11291129
}
11301130
auto restorer{
11311131
messages.SetLocation(arg.sourceLocation().value_or(messages.at()))};
1132-
auto checkActualArgForLabel = [&](evaluate::ActualArgument &arg) {
1132+
auto CheckActualArgForLabel = [&](evaluate::ActualArgument &arg) {
11331133
if (arg.isAlternateReturn()) {
11341134
messages.Say(
11351135
"Alternate return label '%d' cannot be associated with %s"_err_en_US,
11361136
arg.GetLabel(), dummyName);
1137-
return true;
1138-
} else {
11391137
return false;
1138+
} else {
1139+
return true;
11401140
}
11411141
};
11421142
common::visit(
11431143
common::visitors{
11441144
[&](const characteristics::DummyDataObject &object) {
1145-
if (!checkActualArgForLabel(arg)) {
1145+
if (CheckActualArgForLabel(arg)) {
11461146
ConvertBOZLiteralArg(arg, object.type.type());
11471147
if (auto *expr{arg.UnwrapExpr()}) {
11481148
if (auto type{characteristics::TypeAndShape::Characterize(
@@ -1160,9 +1160,16 @@ static void CheckExplicitInterfaceArg(evaluate::ActualArgument &arg,
11601160
evaluate::IsNullObjectPointer(*expr)) {
11611161
// ok, ASSOCIATED(NULL(without MOLD=))
11621162
} else if (object.type.attrs().test(characteristics::
1163-
TypeAndShape::Attr::AssumedRank)) {
1163+
TypeAndShape::Attr::AssumedRank) &&
1164+
evaluate::IsNullObjectPointer(*expr) &&
1165+
(object.attrs.test(
1166+
characteristics::DummyDataObject::Attr::Allocatable) ||
1167+
object.attrs.test(
1168+
characteristics::DummyDataObject::Attr::Pointer) ||
1169+
!object.attrs.test(characteristics::DummyDataObject::
1170+
Attr::Optional))) {
11641171
messages.Say(
1165-
"NULL() without MOLD= must not be associated with an assumed-rank dummy argument"_err_en_US);
1172+
"NULL() without MOLD= must not be associated with an assumed-rank dummy argument that is ALLOCATABLE, POINTER, or non-OPTIONAL"_err_en_US);
11661173
} else if ((object.attrs.test(characteristics::DummyDataObject::
11671174
Attr::Pointer) ||
11681175
object.attrs.test(characteristics::
@@ -1223,7 +1230,7 @@ static void CheckExplicitInterfaceArg(evaluate::ActualArgument &arg,
12231230
}
12241231
},
12251232
[&](const characteristics::DummyProcedure &dummy) {
1226-
if (!checkActualArgForLabel(arg)) {
1233+
if (CheckActualArgForLabel(arg)) {
12271234
CheckProcedureArg(arg, proc, dummy, dummyName, context,
12281235
ignoreImplicitVsExplicit);
12291236
}

flang/test/Semantics/call39.f90

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
22
! Tests actual/dummy pointer argument shape mismatches
33
module m
44
contains
@@ -11,6 +11,15 @@ subroutine s1(p)
1111
subroutine sa(p)
1212
real, pointer, intent(in) :: p(..)
1313
end
14+
subroutine sao(p)
15+
real, intent(in), optional, pointer :: p(..)
16+
end
17+
subroutine so(x)
18+
real, intent(in), optional :: x(..)
19+
end
20+
subroutine soa(a)
21+
real, intent(in), optional, allocatable :: a(..)
22+
end
1423
subroutine test
1524
real, pointer :: a0, a1(:)
1625
call s0(null(a0)) ! ok
@@ -23,9 +32,15 @@ subroutine test
2332
call s1(null(a1)) ! ok
2433
call sa(null(a0)) ! ok
2534
call sa(null(a1)) ! ok
26-
!ERROR: NULL() without MOLD= must not be associated with an assumed-rank dummy argument
27-
call sa(null())
28-
!ERROR: NULL() without MOLD= must not be associated with an assumed-rank dummy argument
35+
!ERROR: NULL() without MOLD= must not be associated with an assumed-rank dummy argument that is ALLOCATABLE, POINTER, or non-OPTIONAL
2936
call sa(null())
37+
call sao ! ok
38+
!ERROR: NULL() without MOLD= must not be associated with an assumed-rank dummy argument that is ALLOCATABLE, POINTER, or non-OPTIONAL
39+
call sao(null())
40+
call so ! ok
41+
call so(null()) ! ok
42+
call soa ! ok
43+
!ERROR: NULL() without MOLD= must not be associated with an assumed-rank dummy argument that is ALLOCATABLE, POINTER, or non-OPTIONAL
44+
call soa(null())
3045
end
3146
end

0 commit comments

Comments
 (0)