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

Conversation

jeanPerier
Copy link
Contributor

Needed for SELECT RANK implementation. I want to stay away from generating the rank > 0 && ... logic in FIR codegen for now.

@jeanPerier jeanPerier requested review from klausler and vzakhari May 30, 2024 18:19
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels May 30, 2024
@llvmbot
Copy link
Member

llvmbot commented May 30, 2024

@llvm/pr-subscribers-flang-runtime

Author: None (jeanPerier)

Changes

Needed for SELECT RANK implementation. I want to stay away from generating the rank > 0 && ... logic in FIR codegen for now.


Full diff: https://github.com/llvm/llvm-project/pull/93857.diff

3 Files Affected:

  • (modified) flang/include/flang/Runtime/support.h (+3)
  • (modified) flang/runtime/support.cpp (+5)
  • (modified) flang/unittests/Runtime/Support.cpp (+11)
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));
+}

@jeanPerier jeanPerier merged commit f49d26b into llvm:main May 31, 2024
10 checks passed
@jeanPerier jeanPerier deleted the jp-is_assumed_size_rt branch May 31, 2024 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants