[flang-commits] [flang] [flang][runtime] add IsAssumedSize API (PR #93857)
via flang-commits
flang-commits at lists.llvm.org
Thu May 30 11:19:17 PDT 2024
https://github.com/jeanPerier created https://github.com/llvm/llvm-project/pull/93857
Needed for SELECT RANK implementation. I want to stay away from generating the `rank > 0 && ...` logic in FIR codegen for now.
>From d0a2a97a4001ff7feeb3d01db81caf2950e79dff Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Thu, 30 May 2024 11:16:19 -0700
Subject: [PATCH] [flang][runtime] add IsAssumedSize API
---
flang/include/flang/Runtime/support.h | 3 +++
flang/runtime/support.cpp | 5 +++++
flang/unittests/Runtime/Support.cpp | 11 +++++++++++
3 files changed, 19 insertions(+)
diff --git a/flang/include/flang/Runtime/support.h b/flang/include/flang/Runtime/support.h
index 8bdf3b9fca83b..ba9c2598bb0dd 100644
--- a/flang/include/flang/Runtime/support.h
+++ b/flang/include/flang/Runtime/support.h
@@ -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
diff --git a/flang/runtime/support.cpp b/flang/runtime/support.cpp
index 19e75429774b3..a607120256d9d 100644
--- a/flang/runtime/support.cpp
+++ b/flang/runtime/support.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "flang/Runtime/support.h"
+#include "ISO_Fortran_util.h"
#include "type-info.h"
#include "flang/Runtime/descriptor.h"
@@ -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) {
diff --git a/flang/unittests/Runtime/Support.cpp b/flang/unittests/Runtime/Support.cpp
index fa2a233e1e654..9d1a417fdbf42 100644
--- a/flang/unittests/Runtime/Support.cpp
+++ b/flang/unittests/Runtime/Support.cpp
@@ -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));
+}
More information about the flang-commits
mailing list