Skip to content

Commit 0cfadb3

Browse files
committed
[flang] Allow NULL() actual argument for pointer dummy
Fixes a bogus error message about an actual argument not being an object. Differential Revision: https://reviews.llvm.org/D95176
1 parent 020c00b commit 0cfadb3

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ static bool DefersSameTypeParameters(
139139
static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
140140
const std::string &dummyName, evaluate::Expr<evaluate::SomeType> &actual,
141141
characteristics::TypeAndShape &actualType, bool isElemental,
142-
bool actualIsArrayElement, evaluate::FoldingContext &context,
143-
const Scope *scope, const evaluate::SpecificIntrinsic *intrinsic) {
142+
evaluate::FoldingContext &context, const Scope *scope,
143+
const evaluate::SpecificIntrinsic *intrinsic) {
144144

145145
// Basic type & rank checking
146146
parser::ContextualMessages &messages{context.messages()};
@@ -153,7 +153,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
153153
characteristics::TypeAndShape::Attr::AssumedRank)) {
154154
} else if (!dummy.type.attrs().test(
155155
characteristics::TypeAndShape::Attr::AssumedShape) &&
156-
(actualType.Rank() > 0 || actualIsArrayElement)) {
156+
(actualType.Rank() > 0 || IsArrayElement(actual))) {
157157
// Sequence association (15.5.2.11) applies -- rank need not match
158158
// if the actual argument is an array or array element designator.
159159
} else {
@@ -271,8 +271,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
271271
? actualLastSymbol->detailsIf<ObjectEntityDetails>()
272272
: nullptr};
273273
int actualRank{evaluate::GetRank(actualType.shape())};
274-
bool actualIsPointer{(actualLastSymbol && IsPointer(*actualLastSymbol)) ||
275-
evaluate::IsNullPointer(actual)};
274+
bool actualIsPointer{evaluate::IsObjectPointer(actual, context)};
276275
if (dummy.type.attrs().test(
277276
characteristics::TypeAndShape::Attr::AssumedShape)) {
278277
// 15.5.2.4(16)
@@ -293,7 +292,9 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
293292
"Coindexed scalar actual argument must be associated with a scalar %s"_err_en_US,
294293
dummyName);
295294
}
296-
if (actualLastSymbol && actualLastSymbol->Rank() == 0 &&
295+
if (!IsArrayElement(actual) &&
296+
!(actualType.type().category() == TypeCategory::Character &&
297+
actualType.type().kind() == 1) &&
297298
!(dummy.type.type().IsAssumedType() && dummyIsAssumedSize)) {
298299
messages.Say(
299300
"Whole scalar actual argument may not be associated with a %s array"_err_en_US,
@@ -624,15 +625,18 @@ static void CheckExplicitInterfaceArg(evaluate::ActualArgument &arg,
624625
arg.set_dummyIntent(object.intent);
625626
bool isElemental{object.type.Rank() == 0 && proc.IsElemental()};
626627
CheckExplicitDataArg(object, dummyName, *expr, *type,
627-
isElemental, IsArrayElement(*expr), context, scope,
628-
intrinsic);
628+
isElemental, context, scope, intrinsic);
629629
} else if (object.type.type().IsTypelessIntrinsicArgument() &&
630630
std::holds_alternative<evaluate::BOZLiteralConstant>(
631631
expr->u)) {
632632
// ok
633633
} else if (object.type.type().IsTypelessIntrinsicArgument() &&
634634
evaluate::IsNullPointer(*expr)) {
635-
// ok, calling ASSOCIATED(NULL())
635+
// ok, ASSOCIATED(NULL())
636+
} else if (object.attrs.test(
637+
characteristics::DummyDataObject::Attr::Pointer) &&
638+
evaluate::IsNullPointer(*expr)) {
639+
// ok, FOO(NULL())
636640
} else {
637641
messages.Say(
638642
"Actual argument '%s' associated with %s is not a variable or typed expression"_err_en_US,

0 commit comments

Comments
 (0)