Skip to content

Commit d0547e4

Browse files
committed
Allow passing to pure
1 parent 1f30465 commit d0547e4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,20 @@ namespace Fortran::semantics {
3030
// - any variable from common blocks except
3131
// - 1-element arrays being single member of COMMON
3232
// - passed to intrinsic
33+
// - passed to PURE procedure
3334
// - avy variable from module except
3435
// - having attribute PARAMETER or PRIVATE
3536
// - having DERIVED type
3637
// - passed to intrinsic
38+
// - passed to PURE procedure
3739
// - being arrays having 1-D rank and is not having ALLOCATABLE or POINTER or
3840
// VOLATILE attributes
3941
static void CheckPassGlobalVariable(
4042
const evaluate::Expr<evaluate::SomeType> &actual,
4143
const parser::ContextualMessages &messages, SemanticsContext &context,
4244
evaluate::FoldingContext &foldingContext,
43-
const evaluate::SpecificIntrinsic *intrinsic) {
45+
const evaluate::SpecificIntrinsic *intrinsic,
46+
const characteristics::Procedure *procedure) {
4447
const Symbol *actualFirstSymbol{evaluate::GetFirstSymbol(actual)};
4548
if (actualFirstSymbol) {
4649
bool warn{false};
@@ -52,6 +55,8 @@ static void CheckPassGlobalVariable(
5255
ownerName = common->name().ToString();
5356
if (intrinsic) {
5457
warn |= false;
58+
} else if (procedure && procedure->IsPure()) {
59+
warn |= false;
5560
} else if (!(actualFirstSymbol->Rank() == 1 &&
5661
actualFirstSymbol->offset() == 0)) {
5762
warn |= true;
@@ -86,6 +91,8 @@ static void CheckPassGlobalVariable(
8691
warn |= false;
8792
} else if (intrinsic) {
8893
warn |= false;
94+
} else if (procedure && procedure->IsPure()) {
95+
warn |= false;
8996
} else if (actualFirstSymbol->Rank() != 1) {
9097
warn |= true;
9198
} else if (!actualFirstSymbol->attrs().test(Attr::ALLOCATABLE) &&
@@ -209,7 +216,7 @@ static void CheckImplicitInterfaceArg(evaluate::ActualArgument &arg,
209216

210217
if (const auto *expr{arg.UnwrapExpr()}) {
211218
CheckPassGlobalVariable(*expr, messages, context, foldingContext,
212-
/*intrinsic=*/nullptr);
219+
/*intrinsic=*/nullptr, /*procedure=*/nullptr);
213220
}
214221
}
215222

@@ -1247,7 +1254,8 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
12471254
"%VAL argument must be a scalar numeric or logical expression"_err_en_US);
12481255
}
12491256

1250-
CheckPassGlobalVariable(actual, messages, context, foldingContext, intrinsic);
1257+
CheckPassGlobalVariable(
1258+
actual, messages, context, foldingContext, intrinsic, &procedure);
12511259
}
12521260

12531261
static void CheckProcedureArg(evaluate::ActualArgument &arg,

0 commit comments

Comments
 (0)