[flang-commits] [flang] [flang][runtime] Teach ApplyType to handle TypeCategory::Unsigned (PR #123058)

via flang-commits flang-commits at lists.llvm.org
Wed Jan 15 05:57:15 PST 2025


https://github.com/macurtis-amd created https://github.com/llvm/llvm-project/pull/123058

None

>From b7039c3f75400788f341a66ba10ce406c7ac5f1b Mon Sep 17 00:00:00 2001
From: Matthew Curtis <macurtis at amd.com>
Date: Wed, 15 Jan 2025 06:49:27 -0600
Subject: [PATCH] [flang][runtime] Teach ApplyType to handle
 TypeCategory::Unsigned

---
 flang/runtime/tools.h               | 17 +++++++++++++++++
 flang/unittests/Runtime/Support.cpp | 11 +++++++++++
 2 files changed, 28 insertions(+)

diff --git a/flang/runtime/tools.h b/flang/runtime/tools.h
index 3fe3283415ba9f..facbd231610570 100644
--- a/flang/runtime/tools.h
+++ b/flang/runtime/tools.h
@@ -206,6 +206,23 @@ inline RT_API_ATTRS RESULT ApplyType(
     default:
       terminator.Crash("not yet implemented: INTEGER(KIND=%d)", kind);
     }
+  case TypeCategory::Unsigned:
+    switch (kind) {
+    case 1:
+      return FUNC<TypeCategory::Unsigned, 1>{}(std::forward<A>(x)...);
+    case 2:
+      return FUNC<TypeCategory::Unsigned, 2>{}(std::forward<A>(x)...);
+    case 4:
+      return FUNC<TypeCategory::Unsigned, 4>{}(std::forward<A>(x)...);
+    case 8:
+      return FUNC<TypeCategory::Unsigned, 8>{}(std::forward<A>(x)...);
+#if defined __SIZEOF_INT128__ && !AVOID_NATIVE_UINT128_T
+    case 16:
+      return FUNC<TypeCategory::Unsigned, 16>{}(std::forward<A>(x)...);
+#endif
+    default:
+      terminator.Crash("not yet implemented: UNSIGNED(KIND=%d)", kind);
+    }
   case TypeCategory::Real:
     switch (kind) {
 #if 0 // TODO: REAL(2 & 3)
diff --git a/flang/unittests/Runtime/Support.cpp b/flang/unittests/Runtime/Support.cpp
index 9d1a417fdbf426..8c8de73b5b9798 100644
--- a/flang/unittests/Runtime/Support.cpp
+++ b/flang/unittests/Runtime/Support.cpp
@@ -67,3 +67,14 @@ TEST(IsAssumedSize, Basic) {
       std::vector<int>{}, std::vector<std::int32_t>{0})};
   EXPECT_FALSE(RTNAME(IsAssumedSize)(*scalar));
 }
+
+TEST(DescriptorBytesFor, Basic) {
+  for (size_t i = 0; i < Fortran::common::TypeCategory_enumSize; ++i) {
+    auto tc{static_cast<TypeCategory>(i)};
+    if (tc == TypeCategory::Derived)
+      continue;
+
+    auto b{Descriptor::BytesFor(tc, 4)};
+    EXPECT_GT(b, 0U);
+  }
+}



More information about the flang-commits mailing list