Index: flang/lib/Evaluate/check-expression.cpp =================================================================== --- flang/lib/Evaluate/check-expression.cpp +++ flang/lib/Evaluate/check-expression.cpp @@ -756,10 +756,16 @@ explicit IsContiguousHelper(FoldingContext &c) : Base{*this}, context_{c} {} using Base::operator(); + template Result operator()(const Constant &) const { + return true; + } + Result operator()(const StaticDataObject &) const { return true; } Result operator()(const semantics::Symbol &symbol) const { const auto &ultimate{symbol.GetUltimate()}; if (ultimate.attrs().test(semantics::Attr::CONTIGUOUS)) { return true; + } else if (!IsVariable(symbol)) { + return true; } else if (ultimate.Rank() == 0) { // Extension: accept scalars as a degenerate case of // simple contiguity to allow their use in contexts like @@ -931,11 +937,7 @@ template std::optional IsContiguous(const A &x, FoldingContext &context) { - if (IsVariable(x)) { - return IsContiguousHelper{context}(x); - } else { - return true; // not a variable - } + return IsContiguousHelper{context}(x); } template std::optional IsContiguous( Index: flang/test/Lower/HLFIR/designators-parameter-array-slice.f90 =================================================================== --- /dev/null +++ flang/test/Lower/HLFIR/designators-parameter-array-slice.f90 @@ -0,0 +1,11 @@ +! Test non-contiguous slice of parameter array. +! RUN: bbc -emit-hlfir --polymorphic-type -o - %s | FileCheck %s +subroutine test2(i) + integer, parameter :: a(*,*) = reshape( [ 1,2,3,4 ], [ 2,2 ]) + integer :: x(2) + x = a(i,:) +end subroutine test2 +! Check that the result type of the designate operation +! is a box (as opposed to !fir.ref>) that is able +! to represent non-contiguous array section: +! CHECK: hlfir.designate {{.*}} shape {{.*}} : (!fir.ref>, i64, index, index, index, !fir.shape<1>) -> !fir.box>