diff --git a/flang/lib/Evaluate/shape.cpp b/flang/lib/Evaluate/shape.cpp --- a/flang/lib/Evaluate/shape.cpp +++ b/flang/lib/Evaluate/shape.cpp @@ -902,18 +902,18 @@ if (maskShape->size() == 0) { // Scalar MASK= -> [MERGE(SIZE(ARRAY=), 0, mask)] if (auto arrayShape{(*this)(call.arguments().at(0))}) { - auto arraySize{GetSize(std::move(*arrayShape))}; - CHECK(arraySize); - ActualArguments toMerge{ - ActualArgument{AsGenericExpr(std::move(*arraySize))}, - ActualArgument{AsGenericExpr(ExtentExpr{0})}, - common::Clone(call.arguments().at(1))}; - auto specific{context_->intrinsics().Probe( - CallCharacteristics{"merge"}, toMerge, *context_)}; - CHECK(specific); - return Shape{ExtentExpr{FunctionRef{ - ProcedureDesignator{std::move(specific->specificIntrinsic)}, - std::move(specific->arguments)}}}; + if (auto arraySize{GetSize(std::move(*arrayShape))}) { + ActualArguments toMerge{ + ActualArgument{AsGenericExpr(std::move(*arraySize))}, + ActualArgument{AsGenericExpr(ExtentExpr{0})}, + common::Clone(call.arguments().at(1))}; + auto specific{context_->intrinsics().Probe( + CallCharacteristics{"merge"}, toMerge, *context_)}; + CHECK(specific); + return Shape{ExtentExpr{FunctionRef{ + ProcedureDesignator{std::move(specific->specificIntrinsic)}, + std::move(specific->arguments)}}}; + } } } else { // Non-scalar MASK= -> [COUNT(mask)] diff --git a/flang/test/Evaluate/errors01.f90 b/flang/test/Evaluate/errors01.f90 --- a/flang/test/Evaluate/errors01.f90 +++ b/flang/test/Evaluate/errors01.f90 @@ -45,6 +45,7 @@ integer :: x(3) !CHECK: error: Invalid 'vector=' argument in PACK: the 'mask=' argument has 3 true elements, but the vector has only 2 elements x = pack(array, mask, [0,0]) + x = pack(spread(array, x(1), x(2)), .true.) ! regression check, once crashed end subroutine subroutine s5 logical, parameter :: mask(2,3) = reshape([.false., .true., .true., .false., .false., .true.], shape(mask))