[flang] Fix bogus errors from SIZE/SHAPE/UBOUND on assumed-shape

While it is indeed an error to use SIZE, SHAPE, or UBOUND on an
assumed-shape dummy argument without also supplying a DIM= argument
to the intrinsic function, it is *not* an error to use these intrinsic
functions on sections or expressions of such arrays.  Refine the test
used for the error message.

Differential Revision: https://reviews.llvm.org/D128391
This commit is contained in:
Peter Klausler 2022-06-17 14:12:13 -07:00
parent 3e610f2cdc
commit b6fce8b92d
3 changed files with 7 additions and 4 deletions

View File

@ -345,7 +345,7 @@ bool IsArrayElement(const Expr<T> &expr, bool intoSubstring = true,
template <typename A>
std::optional<NamedEntity> ExtractNamedEntity(const A &x) {
if (auto dataRef{ExtractDataRef(x, true)}) {
if (auto dataRef{ExtractDataRef(x)}) {
return common::visit(
common::visitors{
[](SymbolRef &&symbol) -> std::optional<NamedEntity> {

View File

@ -1561,14 +1561,14 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
(std::strcmp(name, "shape") == 0 ||
std::strcmp(name, "size") == 0 ||
std::strcmp(name, "ubound") == 0)) {
// Check for an assumed-size array argument.
// Check for a whole assumed-size array argument.
// These are disallowed for SHAPE, and require DIM= for
// SIZE and UBOUND.
// (A previous error message for UBOUND will take precedence
// over this one, as this error is caught by the second entry
// for UBOUND.)
if (const Symbol * argSym{GetLastSymbol(*arg)}) {
if (semantics::IsAssumedSizeArray(*argSym)) {
if (auto named{ExtractNamedEntity(*arg)}) {
if (semantics::IsAssumedSizeArray(named->GetLastSymbol())) {
if (strcmp(name, "shape") == 0) {
messages.Say(arg->sourceLocation(),
"The '%s=' argument to the intrinsic function '%s' may not be assumed-size"_err_en_US,

View File

@ -19,5 +19,8 @@ program test_size
print *, size(array)
print *, ubound(array)
print *, lbound(array)
print *, size(arg(:,1))
print *, ubound(arg(:,1))
print *, shape(arg(:,1))
end subroutine
end