[flang] Catch attempts to use assumed-rank as elemental argument (#159852)

An assumed-rank array may not be used as an argument to an elemental
procedure.

Fixes https://github.com/llvm/llvm-project/issues/159555.
This commit is contained in:
Peter Klausler 2025-09-23 15:45:18 -07:00 committed by GitHub
parent e6da91810e
commit 286f45189b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -1538,6 +1538,10 @@ static bool CheckElementalConformance(parser::ContextualMessages &messages,
evaluate::SayWithDeclaration(messages, *wholeSymbol,
"Whole assumed-size array '%s' may not be used as an argument to an elemental procedure"_err_en_US,
wholeSymbol->name());
} else if (IsAssumedRank(*wholeSymbol)) {
evaluate::SayWithDeclaration(messages, *wholeSymbol,
"Assumed-rank array '%s' may not be used as an argument to an elemental procedure"_err_en_US,
wholeSymbol->name());
}
}
if (auto argShape{evaluate::GetShape(context, *expr)}) {

View File

@ -0,0 +1,13 @@
!RUN: %python %S/test_errors.py %s %flang_fc1
module m
contains
elemental real function f(x)
real, intent(in) :: x
f = x
end
subroutine s(a)
real a(..)
!ERROR: Assumed-rank array 'a' may not be used as an argument to an elemental procedure
print *, f(a)
end
end