[flang-commits] [flang] [flang][cuda] Allow object with SHARED attribute as definable (PR #82822)
via flang-commits
flang-commits at lists.llvm.org
Fri Feb 23 11:56:16 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Valentin Clement (バレンタイン クレメン) (clementval)
<details>
<summary>Changes</summary>
A semantic error was raised in device subprogram like:
```
attributes(global) subroutine devsubr2()
real, shared :: rs
rs = 1
end subroutine
```
Object with the SHARED attribute can be can be read or written by all threads in the block.
https://docs.nvidia.com/hpc-sdk/archive/24.1/compilers/cuda-fortran-prog-guide/index.html#cfpg-var-qual-attr-shared
---
Full diff: https://github.com/llvm/llvm-project/pull/82822.diff
2 Files Affected:
- (modified) flang/lib/Semantics/definable.cpp (+3-2)
- (modified) flang/test/Semantics/cuf03.cuf (+7)
``````````diff
diff --git a/flang/lib/Semantics/definable.cpp b/flang/lib/Semantics/definable.cpp
index 2c57efbb40cd18..5c3fa905d60725 100644
--- a/flang/lib/Semantics/definable.cpp
+++ b/flang/lib/Semantics/definable.cpp
@@ -160,9 +160,10 @@ static std::optional<parser::Message> WhyNotDefinableBase(parser::CharBlock at,
"'%s' is a host-associated allocatable and is not definable in a device subprogram"_err_en_US,
original);
} else if (*cudaDataAttr != common::CUDADataAttr::Device &&
- *cudaDataAttr != common::CUDADataAttr::Managed) {
+ *cudaDataAttr != common::CUDADataAttr::Managed &&
+ *cudaDataAttr != common::CUDADataAttr::Shared) {
return BlameSymbol(at,
- "'%s' is not device or managed data and is not definable in a device subprogram"_err_en_US,
+ "'%s' is not device or managed or shared data and is not definable in a device subprogram"_err_en_US,
original);
}
} else if (!isOwnedByDeviceCode) {
diff --git a/flang/test/Semantics/cuf03.cuf b/flang/test/Semantics/cuf03.cuf
index bebfdadbdbb16b..1b1a3b44b0eded 100644
--- a/flang/test/Semantics/cuf03.cuf
+++ b/flang/test/Semantics/cuf03.cuf
@@ -56,4 +56,11 @@ module m
!WARNING: Pointer 'dp' may not be associated in a device subprogram
real, device, pointer :: dp
end subroutine
+
+ attributes(global) subroutine devsubr2()
+ real, shared :: rs
+
+ rs = 1 ! ok
+ end subroutine
+
end module
``````````
</details>
https://github.com/llvm/llvm-project/pull/82822
More information about the flang-commits
mailing list