diff --git a/flang/lib/Evaluate/fold-designator.cpp b/flang/lib/Evaluate/fold-designator.cpp index 2168383bc7318..d86b44971cc70 100644 --- a/flang/lib/Evaluate/fold-designator.cpp +++ b/flang/lib/Evaluate/fold-designator.cpp @@ -90,6 +90,8 @@ std::optional DesignatorFolder::FoldDesignator( result->Augment((at - lower) * stride); which = quotient; return true; + } else { + isEmpty_ = true; } } return false; @@ -100,16 +102,20 @@ std::optional DesignatorFolder::FoldDesignator( auto end{ToInt64(Fold(context_, triplet.upper().value_or(ExtentExpr{upper})))}; auto step{ToInt64(Fold(context_, triplet.stride()))}; - if (start && end && step && *step != 0) { - ConstantSubscript range{ - (*end - *start + *step) / *step}; - if (range > 0) { - auto quotient{which / range}; - auto remainder{which - range * quotient}; - auto j{*start + remainder * *step}; - result->Augment((j - lower) * stride); - which = quotient; - return true; + if (start && end && step) { + if (*step != 0) { + ConstantSubscript range{ + (*end - *start + *step) / *step}; + if (range > 0) { + auto quotient{which / range}; + auto remainder{which - range * quotient}; + auto j{*start + remainder * *step}; + result->Augment((j - lower) * stride); + which = quotient; + return true; + } else { + isEmpty_ = true; + } } } return false; diff --git a/flang/test/Semantics/data05.f90 b/flang/test/Semantics/data05.f90 index 35b9ed1548d60..02bfd46632645 100644 --- a/flang/test/Semantics/data05.f90 +++ b/flang/test/Semantics/data05.f90 @@ -89,4 +89,8 @@ subroutine s12 procedure(rfunc), pointer :: pp ! CHECK: pp, EXTERNAL, POINTER (Function, InDataStmt) size=8 offset=0: ProcEntity rfunc => rfunc2 data pp/rfunc2/ end subroutine + subroutine s13 + integer j(2) + data j(2:1), j(1:2) /1,2/ ! CHECK: j (InDataStmt) size=8 offset=0: ObjectEntity type: INTEGER(4) shape: 1_8:2_8 init:[INTEGER(4)::1_4,2_4] + end subroutine end module