[flang-commits] [flang] [flang][cuda] Enforce PINNED attribute when ALLOCATE with PINNED option (PR #89455)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Fri Apr 19 14:07:35 PDT 2024


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/89455

When the PINNED option is specified on an ALLOCATE statement, the object must have the PINNED attribute.

>From e22a0e455bcf57d25b5ccf7beb9e7aa4393e78ec Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 19 Apr 2024 14:06:04 -0700
Subject: [PATCH] [flang][cuda] Enforce PINNED attribute when ALLOCATE with
 PINNED option

---
 flang/lib/Semantics/check-allocate.cpp | 7 +++++++
 flang/test/Semantics/cuf07.cuf         | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/flang/lib/Semantics/check-allocate.cpp b/flang/lib/Semantics/check-allocate.cpp
index a7244e1c58330a..7bfd86262b3d62 100644
--- a/flang/lib/Semantics/check-allocate.cpp
+++ b/flang/lib/Semantics/check-allocate.cpp
@@ -611,6 +611,13 @@ bool AllocationCheckerHelper::RunChecks(SemanticsContext &context) {
       return false;
     }
   }
+  if (allocateInfo_.gotPinned) {
+    std::optional<common::CUDADataAttr> cudaAttr{GetCUDADataAttr(ultimate_)};
+    if (!cudaAttr || *cudaAttr != common::CUDADataAttr::Pinned) {
+      context.Say(name_.source,
+          "Object in ALLOCATE must have PINNED attribute when PINNED option is specified"_err_en_US);
+    }
+  }
   return RunCoarrayRelatedChecks(context);
 }
 
diff --git a/flang/test/Semantics/cuf07.cuf b/flang/test/Semantics/cuf07.cuf
index b520b5da51264b..91a78e124c593b 100644
--- a/flang/test/Semantics/cuf07.cuf
+++ b/flang/test/Semantics/cuf07.cuf
@@ -23,4 +23,12 @@ module m
     !BECAUSE: 'ma' is a host-associated allocatable and is not definable in a device subprogram
     deallocate(ma)
   end subroutine
+
+  subroutine hostsub()
+    integer, allocatable, device :: ia(:)
+    logical :: plog
+
+    !ERROR: Object in ALLOCATE must have PINNED attribute when PINNED option is specified
+    allocate(ia(100), pinned = plog)
+  end subroutine
 end module



More information about the flang-commits mailing list