[flang-commits] [PATCH] D145248: [flang] Ensure that CLASS(*) component descriptors have addenda
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Fri Mar 3 08:29:33 PST 2023
klausler created this revision.
klausler added a reviewer: clementval.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
In the calculation of derived type component byte sizes, ensure
that CLASS(*) unlimited polymorphic components have space allocated
for their addenda.
https://reviews.llvm.org/D145248
Files:
flang/lib/Semantics/compute-offsets.cpp
flang/runtime/derived.cpp
Index: flang/runtime/derived.cpp
===================================================================
--- flang/runtime/derived.cpp
+++ flang/runtime/derived.cpp
@@ -20,8 +20,8 @@
std::size_t elements{instance.Elements()};
std::size_t byteStride{instance.ElementBytes()};
int stat{StatOk};
- // Initialize data components in each element; the per-element iteration
- // constitutes the inner loops, not outer
+ // Initialize data components in each element; the per-element iterations
+ // constitute the inner loops, not the outer ones
std::size_t myComponents{componentDesc.Elements()};
for (std::size_t k{0}; k < myComponents; ++k) {
const auto &comp{
@@ -36,7 +36,14 @@
if (comp.genre() == typeInfo::Component::Genre::Automatic) {
stat = ReturnError(terminator, allocDesc.Allocate(), errMsg, hasStat);
if (stat == StatOk) {
- stat = Initialize(allocDesc, derived, terminator, hasStat, errMsg);
+ if (const DescriptorAddendum * addendum{allocDesc.Addendum()}) {
+ if (const auto *derived{addendum->derivedType()}) {
+ if (!derived->noInitializationNeeded()) {
+ stat = Initialize(
+ allocDesc, *derived, terminator, hasStat, errMsg);
+ }
+ }
+ }
}
if (stat != StatOk) {
break;
Index: flang/lib/Semantics/compute-offsets.cpp
===================================================================
--- flang/lib/Semantics/compute-offsets.cpp
+++ flang/lib/Semantics/compute-offsets.cpp
@@ -321,11 +321,12 @@
const Symbol &symbol, bool entire) -> SizeAndAlignment {
auto &targetCharacteristics{context_.targetCharacteristics()};
if (IsDescriptor(symbol)) {
- const auto *derived{
- evaluate::GetDerivedTypeSpec(evaluate::DynamicType::From(symbol))};
+ auto dyType{evaluate::DynamicType::From(symbol)};
+ const auto *derived{evaluate::GetDerivedTypeSpec(dyType)};
int lenParams{derived ? CountLenParameters(*derived) : 0};
+ bool needAddendum{derived || (dyType && dyType->IsUnlimitedPolymorphic())};
std::size_t size{runtime::Descriptor::SizeInBytes(
- symbol.Rank(), derived != nullptr, lenParams)};
+ symbol.Rank(), needAddendum, lenParams)};
return {size, targetCharacteristics.descriptorAlignment()};
}
if (IsProcedurePointer(symbol)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145248.502140.patch
Type: text/x-patch
Size: 2418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230303/c0f8074f/attachment-0001.bin>
More information about the flang-commits
mailing list