Skip to content

Commit 07b9a44

Browse files
committed
[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
1 parent 2e0ef17 commit 07b9a44

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

flang/runtime/type-info.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,14 @@ void Component::EstablishDescriptor(Descriptor &descriptor,
8989
const Descriptor &container, Terminator &terminator) const {
9090
TypeCategory cat{category()};
9191
if (cat == TypeCategory::Character) {
92-
auto length{characterLen_.GetValue(&container)};
93-
RUNTIME_CHECK(terminator, length.has_value());
94-
descriptor.Establish(kind_, *length / kind_, nullptr, rank_);
92+
std::size_t lengthInChars{0};
93+
if (auto length{characterLen_.GetValue(&container)}) {
94+
lengthInChars = static_cast<std::size_t>(*length / kind_);
95+
} else {
96+
RUNTIME_CHECK(
97+
terminator, characterLen_.genre() == Value::Genre::Deferred);
98+
}
99+
descriptor.Establish(kind_, lengthInChars, nullptr, rank_);
95100
} else if (cat == TypeCategory::Derived) {
96101
const DerivedType *type{derivedType()};
97102
RUNTIME_CHECK(terminator, type != nullptr);

flang/runtime/type-info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Value {
3838
Explicit = 2,
3939
LenParameter = 3
4040
};
41-
41+
Genre genre() const { return genre_; }
4242
std::optional<TypeParameterValue> GetValue(const Descriptor *) const;
4343

4444
private:

0 commit comments

Comments
 (0)