[flang-commits] [PATCH] D119731: [flang] Allow for deferred-length character in EstablishDescriptor
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Mon Feb 14 09:03:06 PST 2022
klausler created this revision.
klausler added a reviewer: jeanPerier.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.
When the runtime is initializing an instance of a derived type,
don't crash if an allocatable character component has deferred length.
https://reviews.llvm.org/D119731
Files:
flang/runtime/type-info.cpp
flang/runtime/type-info.h
Index: flang/runtime/type-info.h
===================================================================
--- flang/runtime/type-info.h
+++ flang/runtime/type-info.h
@@ -38,7 +38,7 @@
Explicit = 2,
LenParameter = 3
};
-
+ Genre genre() const { return genre_; }
std::optional<TypeParameterValue> GetValue(const Descriptor *) const;
private:
Index: flang/runtime/type-info.cpp
===================================================================
--- flang/runtime/type-info.cpp
+++ flang/runtime/type-info.cpp
@@ -89,9 +89,14 @@
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119731.408445.patch
Type: text/x-patch
Size: 1336 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220214/dd76432b/attachment.bin>
More information about the flang-commits
mailing list