[flang-commits] [PATCH] D130383: [flang] Don't fold zero-length substring references

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jul 22 12:14:32 PDT 2022


klausler created this revision.
klausler added a reviewer: jeanPerier.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

In some contexts the code looks cleaner if we fold zero-length substring
references into empty character constants, but those don't work in
variable definition contexts and can lead to bogus semantic error
messages.


https://reviews.llvm.org/D130383

Files:
  flang/lib/Evaluate/fold-implementation.h


Index: flang/lib/Evaluate/fold-implementation.h
===================================================================
--- flang/lib/Evaluate/fold-implementation.h
+++ flang/lib/Evaluate/fold-implementation.h
@@ -342,11 +342,9 @@
           return std::move(*specific);
         }
       }
-      if (auto length{ToInt64(Fold(context_, substring->LEN()))}) {
-        if (*length == 0) {
-          return Expr<T>{Constant<T>{Scalar<T>{}}};
-        }
-      }
+      // We used to fold zero-length substrings into zero-length
+      // constants here, but that led to problems in variable
+      // definition contexts.
     }
   } else if constexpr (T::category == TypeCategory::Real) {
     if (auto *zPart{std::get_if<ComplexPart>(&designator.u)}) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130383.446930.patch
Type: text/x-patch
Size: 751 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220722/61dd07f3/attachment.bin>


More information about the flang-commits mailing list