From: peter klausler Date: Tue, 7 May 2019 23:24:50 +0000 (-0700) Subject: [flang] Fix folding of substring X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb83471e96e83c0b0fe6b28b2c97429f8880fe6f;p=platform%2Fupstream%2Fllvm.git [flang] Fix folding of substring Original-commit: flang-compiler/f18@62dc5e0c93d9f051ef936ee7a281240fe3657b35 Reviewed-on: https://github.com/flang-compiler/f18/pull/449 Tree-same-pre-rewrite: false --- diff --git a/flang/lib/evaluate/fold.cc b/flang/lib/evaluate/fold.cc index 17d7741..c6f8144 100644 --- a/flang/lib/evaluate/fold.cc +++ b/flang/lib/evaluate/fold.cc @@ -158,8 +158,13 @@ DataRef FoldOperation(FoldingContext &context, DataRef &&dataRef) { } Substring FoldOperation(FoldingContext &context, Substring &&substring) { - std::optional> lower{Fold(context, substring.lower())}; - std::optional> upper{Fold(context, substring.upper())}; + std::optional> 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()}) { return Substring{FoldOperation(context, DataRef{*dataRef}), std::move(lower), std::move(upper)};