Skip to content

Commit

Permalink
[flang] Ensure that CLASS(*) component descriptors have addenda
Browse files Browse the repository at this point in the history
In the calculation of derived type component byte sizes, ensure
that CLASS(*) unlimited polymorphic components have space allocated
for their addenda.

Differential Revision: https://reviews.llvm.org/D145248
  • Loading branch information
klausler committed Mar 9, 2023
1 parent d7323f6 commit 392173d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 4 additions & 3 deletions flang/lib/Semantics/compute-offsets.cpp
Expand Up @@ -321,11 +321,12 @@ auto ComputeOffsetsHelper::GetSizeAndAlignment(
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)) {
Expand Down
13 changes: 10 additions & 3 deletions flang/runtime/derived.cpp
Expand Up @@ -20,8 +20,8 @@ int Initialize(const Descriptor &instance, const typeInfo::DerivedType &derived,
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{
Expand All @@ -36,7 +36,14 @@ int Initialize(const Descriptor &instance, const typeInfo::DerivedType &derived,
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;
Expand Down

0 comments on commit 392173d

Please sign in to comment.