Skip to content

[flang][runtime] add IsAssumedSize API #93857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions flang/include/flang/Runtime/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ extern "C" {
// Predicate: is the storage described by a Descriptor contiguous in memory?
bool RTDECL(IsContiguous)(const Descriptor &);

// Predicate: is this descriptor describing an assumed-size array?
bool RTDECL(IsAssumedSize)(const Descriptor &);

// Copy "from" descriptor into "to" descriptor and update "to" dynamic type,
// CFI_attribute, and lower bounds according to the other arguments.
// "newDynamicType" may be a null pointer in which case "to" dynamic type is the
Expand Down
5 changes: 5 additions & 0 deletions flang/runtime/support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "flang/Runtime/support.h"
#include "ISO_Fortran_util.h"
#include "type-info.h"
#include "flang/Runtime/descriptor.h"

Expand All @@ -18,6 +19,10 @@ bool RTDEF(IsContiguous)(const Descriptor &descriptor) {
return descriptor.IsContiguous();
}

bool RTDEF(IsAssumedSize)(const Descriptor &descriptor) {
return ISO::IsAssumedSize(&descriptor.raw());
}

void RTDEF(CopyAndUpdateDescriptor)(Descriptor &to, const Descriptor &from,
const typeInfo::DerivedType *newDynamicType,
ISO::CFI_attribute_t newAttribute, enum LowerBoundModifier newLowerBounds) {
Expand Down
11 changes: 11 additions & 0 deletions flang/unittests/Runtime/Support.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ TEST(CopyAndUpdateDescriptor, Basic) {
EXPECT_EQ(result.GetDimension(1).Extent(), x->GetDimension(1).Extent());
EXPECT_EQ(result.GetDimension(1).LowerBound(), 1);
}

TEST(IsAssumedSize, Basic) {
auto x{MakeArray<TypeCategory::Integer, 4>(
std::vector<int>{2, 3}, std::vector<std::int32_t>{0, 1, 2, 3, 4, 5})};
EXPECT_FALSE(RTNAME(IsAssumedSize)(*x));
x->GetDimension(1).SetExtent(-1);
EXPECT_TRUE(RTNAME(IsAssumedSize)(*x));
auto scalar{MakeArray<TypeCategory::Integer, 4>(
std::vector<int>{}, std::vector<std::int32_t>{0})};
EXPECT_FALSE(RTNAME(IsAssumedSize)(*scalar));
}
Loading