Skip to content

Commit 1595ca4

Browse files
authored
[flang] Catch whole assumed-size array passed to elemental (llvm#108239)
A whole assumed-size array is not a valid argument to an elemental procedure (intrinsic or otherwise).
1 parent 1d3bcf9 commit 1595ca4

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,14 @@ static bool CheckElementalConformance(parser::ContextualMessages &messages,
13631363
const auto &dummy{proc.dummyArguments.at(index++)};
13641364
if (arg) {
13651365
if (const auto *expr{arg->UnwrapExpr()}) {
1366+
if (const auto *wholeSymbol{evaluate::UnwrapWholeSymbolDataRef(arg)}) {
1367+
wholeSymbol = &ResolveAssociations(*wholeSymbol);
1368+
if (IsAssumedSizeArray(*wholeSymbol)) {
1369+
evaluate::SayWithDeclaration(messages, *wholeSymbol,
1370+
"Whole assumed-size array '%s' may not be used as an argument to an elemental procedure"_err_en_US,
1371+
wholeSymbol->name());
1372+
}
1373+
}
13661374
if (auto argShape{evaluate::GetShape(context, *expr)}) {
13671375
if (GetRank(*argShape) > 0) {
13681376
std::string argName{"actual argument ("s + expr->AsFortran() +

flang/test/Semantics/elemental02.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
subroutine s(a)
3+
real a(*)
4+
interface
5+
elemental function ef(efarg)
6+
real, intent(in) :: efarg
7+
end
8+
end interface
9+
!ERROR: Whole assumed-size array 'a' may not be used as an argument to an elemental procedure
10+
print *, sqrt(a)
11+
!ERROR: Whole assumed-size array 'a' may not be used as an argument to an elemental procedure
12+
print *, ef(a)
13+
end

0 commit comments

Comments
 (0)