[llvm-branch-commits] [flang] [flang][cuda] Record implicit pinned attribution in module files (PR #225315)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Sep 22 00:16:25 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Kareem Ergawy (ergawy)
<details>
<summary>Changes</summary>
Under `-gpu=mem:pinned` an unattributed `ALLOCATABLE` is attributed as `pinned` by the compiler. The module file therefore spelled an implicitly applied `PINNED` the same as one the user wrote, and a reader treated it as a user requirement: adding `-gpu=mem:pinned` to a module's build rejected its OpenACC-only consumers over an attribute the user never wrote.
Record the implicit attribution for pinned as well, so it is written as `PINNED(IMPLICIT)` and consumers can tell the two apart.
---
Full diff: https://github.com/llvm/llvm-project/pull/225315.diff
2 Files Affected:
- (modified) flang/lib/Semantics/resolve-names.cpp (+3-1)
- (added) flang/test/Semantics/CUDA/cuda-pinned-implicit-modfile.cuf (+42)
``````````diff
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 8a2ffc1c20f1b..570c13789a097 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -11018,8 +11018,10 @@ void ResolveNamesVisitor::FinishSpecificationPart(
// enabled.
else if (IsAllocatable(symbol) &&
context().languageFeatures().IsEnabled(
- common::LanguageFeature::CudaPinned))
+ common::LanguageFeature::CudaPinned)) {
object->set_cudaDataAttr(common::CUDADataAttr::Pinned);
+ object->set_cudaDataAttrIsImplicit();
+ }
}
}
}
diff --git a/flang/test/Semantics/CUDA/cuda-pinned-implicit-modfile.cuf b/flang/test/Semantics/CUDA/cuda-pinned-implicit-modfile.cuf
new file mode 100644
index 0000000000000..e9a4170c20c95
--- /dev/null
+++ b/flang/test/Semantics/CUDA/cuda-pinned-implicit-modfile.cuf
@@ -0,0 +1,42 @@
+! Under -gpu=pinned the compiler attributes unattributed ALLOCATABLEs as
+! pinned on the user's behalf, exactly as -gpu=managed attributes them as
+! managed. A module file records that it did so, with the (IMPLICIT)
+! qualifier, so that a reader can tell such an attribute from one the user
+! wrote.
+
+! RUN: rm -rf %t && split-file %s %t
+! RUN: cd %t && bbc -emit-hlfir -fcuda -gpu=pinned def.cuf -o /dev/null
+! RUN: cat %t/m.mod | FileCheck %s --check-prefix=MODFILE
+
+! An attribute the compiler applied does not make the module a definer of CUDA
+! symbols, so a consumer without CUDA Fortran enabled is not rejected.
+! RUN: cd %t && bbc -emit-hlfir -fopenacc use_acc.cuf -o /dev/null
+
+! One the user wrote still is, and still rejects such a consumer.
+! RUN: cd %t && bbc -emit-hlfir -fcuda def_explicit.cuf -o /dev/null
+! RUN: cd %t && not bbc -emit-hlfir -fopenacc use_acc_explicit.cuf -o /dev/null 2>&1 \
+! RUN: | FileCheck %s --check-prefix=EXPLICIT
+
+!--- def.cuf
+module m
+ real, allocatable :: implicit_var(:)
+end module
+
+! MODFILE: real(4),allocatable,pinned(implicit)::implicit_var(:)
+
+!--- use_acc.cuf
+subroutine acc_only()
+ use m
+end subroutine
+
+!--- def_explicit.cuf
+module m_explicit
+ real, allocatable, pinned :: explicit_var(:)
+end module
+
+!--- use_acc_explicit.cuf
+subroutine acc_only_explicit()
+ use m_explicit
+end subroutine
+
+! EXPLICIT: error: Cannot use module file for module 'm_explicit': CUDA is not enabled, but '{{.*}}m_explicit.mod' defines CUDA symbols
``````````
</details>
https://github.com/llvm/llvm-project/pull/225315
More information about the llvm-branch-commits
mailing list