aboutsummaryrefslogtreecommitdiff
path: root/flang
diff options
context:
space:
mode:
authorPeter Klausler <pklausler@nvidia.com>2022-07-18 13:13:03 -0700
committerPeter Klausler <pklausler@nvidia.com>2022-07-23 10:08:09 -0700
commit3096b85696cc71a6b6798c6883712f7ea6a6b576 (patch)
tree2a7091a03604b5927a506ca3e484fc045757cbbe /flang
parent1b4b12a34022b13b35755d9c941f7f13753e5e96 (diff)
downloadllvm-3096b85696cc71a6b6798c6883712f7ea6a6b576.zip
llvm-3096b85696cc71a6b6798c6883712f7ea6a6b576.tar.gz
llvm-3096b85696cc71a6b6798c6883712f7ea6a6b576.tar.bz2
[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
Diffstat (limited to 'flang')
-rw-r--r--flang/lib/Evaluate/fold-implementation.h8
1 files changed, 3 insertions, 5 deletions
diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h
index daa3f0a..37f4f8d 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)}) {