Skip to content

Commit f49d26b

Browse files
authored
[flang][runtime] add IsAssumedSize API (#93857)
Needed for SELECT RANK implementation. I want to stay away from generating the `rank > 0 && ...` logic in FIR codegen for now.
1 parent 4985f25 commit f49d26b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

flang/include/flang/Runtime/support.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ extern "C" {
3434
// Predicate: is the storage described by a Descriptor contiguous in memory?
3535
bool RTDECL(IsContiguous)(const Descriptor &);
3636

37+
// Predicate: is this descriptor describing an assumed-size array?
38+
bool RTDECL(IsAssumedSize)(const Descriptor &);
39+
3740
// Copy "from" descriptor into "to" descriptor and update "to" dynamic type,
3841
// CFI_attribute, and lower bounds according to the other arguments.
3942
// "newDynamicType" may be a null pointer in which case "to" dynamic type is the

flang/runtime/support.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "flang/Runtime/support.h"
10+
#include "ISO_Fortran_util.h"
1011
#include "type-info.h"
1112
#include "flang/Runtime/descriptor.h"
1213

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

22+
bool RTDEF(IsAssumedSize)(const Descriptor &descriptor) {
23+
return ISO::IsAssumedSize(&descriptor.raw());
24+
}
25+
2126
void RTDEF(CopyAndUpdateDescriptor)(Descriptor &to, const Descriptor &from,
2227
const typeInfo::DerivedType *newDynamicType,
2328
ISO::CFI_attribute_t newAttribute, enum LowerBoundModifier newLowerBounds) {

flang/unittests/Runtime/Support.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ TEST(CopyAndUpdateDescriptor, Basic) {
5656
EXPECT_EQ(result.GetDimension(1).Extent(), x->GetDimension(1).Extent());
5757
EXPECT_EQ(result.GetDimension(1).LowerBound(), 1);
5858
}
59+
60+
TEST(IsAssumedSize, Basic) {
61+
auto x{MakeArray<TypeCategory::Integer, 4>(
62+
std::vector<int>{2, 3}, std::vector<std::int32_t>{0, 1, 2, 3, 4, 5})};
63+
EXPECT_FALSE(RTNAME(IsAssumedSize)(*x));
64+
x->GetDimension(1).SetExtent(-1);
65+
EXPECT_TRUE(RTNAME(IsAssumedSize)(*x));
66+
auto scalar{MakeArray<TypeCategory::Integer, 4>(
67+
std::vector<int>{}, std::vector<std::int32_t>{0})};
68+
EXPECT_FALSE(RTNAME(IsAssumedSize)(*scalar));
69+
}

0 commit comments

Comments
 (0)