[flang-commits] [flang] 5c90527 - [flang][cuda] Allow object with SHARED attribute as definable (#82822)
via flang-commits
flang-commits at lists.llvm.org
Fri Feb 23 12:56:44 PST 2024
Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-02-23T12:56:41-08:00
New Revision: 5c90527b436d1c7d753c187aff1b45e6c8da1af6
URL: https://github.com/llvm/llvm-project/commit/5c90527b436d1c7d753c187aff1b45e6c8da1af6
DIFF: https://github.com/llvm/llvm-project/commit/5c90527b436d1c7d753c187aff1b45e6c8da1af6.diff
LOG: [flang][cuda] Allow object with SHARED attribute as definable (#82822)
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
Added:
Modified:
flang/lib/Semantics/definable.cpp
flang/test/Semantics/cuf03.cuf
Removed:
################################################################################
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 4260d7edd626f9..41bfbb76781364 100644
--- a/flang/test/Semantics/cuf03.cuf
+++ b/flang/test/Semantics/cuf03.cuf
@@ -62,4 +62,11 @@ module m
!ERROR: Object 'rc' with ATTRIBUTES(CONSTANT) may not be declared in a host subprogram
real, constant :: rc
end subroutine
+
+ attributes(global) subroutine devsubr2()
+ real, shared :: rs
+
+ rs = 1 ! ok
+ end subroutine
+
end module
More information about the flang-commits
mailing list