[flang-commits] [flang] 3096b85 - [flang] Don't fold zero-length substring references
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Sat Jul 23 10:08:25 PDT 2022
Author: Peter Klausler
Date: 2022-07-23T10:08:09-07:00
New Revision: 3096b85696cc71a6b6798c6883712f7ea6a6b576
URL: https://github.com/llvm/llvm-project/commit/3096b85696cc71a6b6798c6883712f7ea6a6b576
DIFF: https://github.com/llvm/llvm-project/commit/3096b85696cc71a6b6798c6883712f7ea6a6b576.diff
LOG: [flang] Don't fold zero-length substring references
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.
Differential Revision: https://reviews.llvm.org/D130383
Added:
Modified:
flang/lib/Evaluate/fold-implementation.h
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index daa3f0a6512d..37f4f8db996f 100644
--- a/flang/lib/Evaluate/fold-implementation.h
+++ b/flang/lib/Evaluate/fold-implementation.h
@@ -342,11 +342,9 @@ template <typename T> Expr<T> Folder<T>::Folding(Designator<T> &&designator) {
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)}) {
More information about the flang-commits
mailing list