Skip to content
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

[flang][cuda] Enforce PINNED attribute when ALLOCATE with PINNED option #89455

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

clementval
Copy link
Contributor

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

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Apr 19, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 19, 2024

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

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


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-allocate.cpp (+7)
  • (modified) flang/test/Semantics/cuf07.cuf (+8)
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

@clementval clementval merged commit 16e3464 into llvm:main Apr 19, 2024
6 of 7 checks passed
@clementval clementval deleted the cuda_pinned_sema branch April 19, 2024 21:58
aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 21, 2024
…on (llvm#89455)

When the PINNED option is specified on an ALLOCATE statement, the object
must have the PINNED attribute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants