[flang-commits] [flang] 07b9a44 - [flang] Allow for deferred-length character in EstablishDescriptor
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Feb 14 10:05:13 PST 2022
Author: Peter Klausler
Date: 2022-02-14T10:05:07-08:00
New Revision: 07b9a44515eba580ba181a5c84118fb31f80e80f
URL: https://github.com/llvm/llvm-project/commit/07b9a44515eba580ba181a5c84118fb31f80e80f
DIFF: https://github.com/llvm/llvm-project/commit/07b9a44515eba580ba181a5c84118fb31f80e80f.diff
LOG: [flang] Allow for deferred-length character in EstablishDescriptor
When the runtime is initializing an instance of a derived type,
don't crash if an allocatable character component has deferred length.
Differential Revision: https://reviews.llvm.org/D119731
Added:
Modified:
flang/runtime/type-info.cpp
flang/runtime/type-info.h
Removed:
################################################################################
diff --git a/flang/runtime/type-info.cpp b/flang/runtime/type-info.cpp
index 37c3c1f5ab86..8f66aeab4079 100644
--- a/flang/runtime/type-info.cpp
+++ b/flang/runtime/type-info.cpp
@@ -89,9 +89,14 @@ void Component::EstablishDescriptor(Descriptor &descriptor,
const Descriptor &container, Terminator &terminator) const {
TypeCategory cat{category()};
if (cat == TypeCategory::Character) {
- auto length{characterLen_.GetValue(&container)};
- RUNTIME_CHECK(terminator, length.has_value());
- descriptor.Establish(kind_, *length / kind_, nullptr, rank_);
+ std::size_t lengthInChars{0};
+ if (auto length{characterLen_.GetValue(&container)}) {
+ lengthInChars = static_cast<std::size_t>(*length / kind_);
+ } else {
+ RUNTIME_CHECK(
+ terminator, characterLen_.genre() == Value::Genre::Deferred);
+ }
+ descriptor.Establish(kind_, lengthInChars, nullptr, rank_);
} else if (cat == TypeCategory::Derived) {
const DerivedType *type{derivedType()};
RUNTIME_CHECK(terminator, type != nullptr);
diff --git a/flang/runtime/type-info.h b/flang/runtime/type-info.h
index 62b8c6c3cbae..747f0342f87d 100644
--- a/flang/runtime/type-info.h
+++ b/flang/runtime/type-info.h
@@ -38,7 +38,7 @@ class Value {
Explicit = 2,
LenParameter = 3
};
-
+ Genre genre() const { return genre_; }
std::optional<TypeParameterValue> GetValue(const Descriptor *) const;
private:
More information about the flang-commits
mailing list