[flang] Fix folding of substring

Original-commit: flang-compiler/f18@62dc5e0c93
Reviewed-on: https://github.com/flang-compiler/f18/pull/449
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2019-05-07 16:24:50 -07:00
parent 52d46695fc
commit bb83471e96
1 changed files with 7 additions and 2 deletions

View File

@ -158,8 +158,13 @@ DataRef FoldOperation(FoldingContext &context, DataRef &&dataRef) {
}
Substring FoldOperation(FoldingContext &context, Substring &&substring) {
std::optional<Expr<SubscriptInteger>> lower{Fold(context, substring.lower())};
std::optional<Expr<SubscriptInteger>> upper{Fold(context, substring.upper())};
std::optional<Expr<SubscriptInteger>> lower, upper;
if (auto *p{substring.lower()}) {
lower = Fold(context, std::move(*p));
}
if (auto *p{substring.upper()}) {
upper = Fold(context, std::move(*p));
}
if (const DataRef * dataRef{substring.GetParentIf<DataRef>()}) {
return Substring{FoldOperation(context, DataRef{*dataRef}),
std::move(lower), std::move(upper)};