[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
This commit is contained in:
Peter Klausler 2022-02-11 10:37:55 -08:00
parent 2e0ef179d8
commit 07b9a44515
2 changed files with 9 additions and 4 deletions

View File

@ -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);

View File

@ -38,7 +38,7 @@ public:
Explicit = 2,
LenParameter = 3
};
Genre genre() const { return genre_; }
std::optional<TypeParameterValue> GetValue(const Descriptor *) const;
private: