Skip to content

Commit

Permalink
[flang] Handle empty array references in DATA statements
Browse files Browse the repository at this point in the history
When an array reference in a DATA statement is empty due to an
empty vector subscript or a section lower bound being higher than
its upper bound with a positive stride (or lower with negative),
ensure that isEmpty() is correct afterwards so that such an empty
array reference doesn't terminate processing of that DATA statement
block.

Fixes #63512.

Differential Revision: https://reviews.llvm.org/D153799
  • Loading branch information
klausler committed Jun 27, 2023
1 parent 5b55eb1 commit 59f0959
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 16 additions & 10 deletions flang/lib/Evaluate/fold-designator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ std::optional<OffsetSymbol> DesignatorFolder::FoldDesignator(
result->Augment((at - lower) * stride);
which = quotient;
return true;
} else {
isEmpty_ = true;
}
}
return false;
Expand All @@ -100,16 +102,20 @@ std::optional<OffsetSymbol> 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;
Expand Down
4 changes: 4 additions & 0 deletions flang/test/Semantics/data05.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 59f0959

Please sign in to comment.