diff --git a/flang/include/flang/Evaluate/shape.h b/flang/include/flang/Evaluate/shape.h --- a/flang/include/flang/Evaluate/shape.h +++ b/flang/include/flang/Evaluate/shape.h @@ -168,8 +168,9 @@ return common::visit( common::visitors{ [&](const Expr &x) -> MaybeExtentExpr { - if (auto xShape{ - context_ ? GetShape(*context_, x) : GetShape(x)}) { + if (auto xShape{!useResultSymbolShape_ ? (*this)(x) + : context_ ? GetShape(*context_, x) + : GetShape(x)}) { // Array values in array constructors get linearized. return GetSize(std::move(*xShape)); } else { diff --git a/flang/test/Evaluate/rewrite01.f90 b/flang/test/Evaluate/rewrite01.f90 --- a/flang/test/Evaluate/rewrite01.f90 +++ b/flang/test/Evaluate/rewrite01.f90 @@ -195,4 +195,15 @@ end associate end subroutine +!CHECK-LABEL: array_constructor +subroutine array_constructor() + interface + function return_allocatable() + real, allocatable :: return_allocatable(:) + end function + end interface + !CHECK: PRINT *, size([REAL(4)::return_allocatable(),return_allocatable()]) + print *, size([return_allocatable(), return_allocatable()]) +end subroutine + end module