Skip to content

Commit 5c90527

Browse files
authored
[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
1 parent 99f31ba commit 5c90527

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

flang/lib/Semantics/definable.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ static std::optional<parser::Message> WhyNotDefinableBase(parser::CharBlock at,
160160
"'%s' is a host-associated allocatable and is not definable in a device subprogram"_err_en_US,
161161
original);
162162
} else if (*cudaDataAttr != common::CUDADataAttr::Device &&
163-
*cudaDataAttr != common::CUDADataAttr::Managed) {
163+
*cudaDataAttr != common::CUDADataAttr::Managed &&
164+
*cudaDataAttr != common::CUDADataAttr::Shared) {
164165
return BlameSymbol(at,
165-
"'%s' is not device or managed data and is not definable in a device subprogram"_err_en_US,
166+
"'%s' is not device or managed or shared data and is not definable in a device subprogram"_err_en_US,
166167
original);
167168
}
168169
} else if (!isOwnedByDeviceCode) {

flang/test/Semantics/cuf03.cuf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,11 @@ module m
6262
!ERROR: Object 'rc' with ATTRIBUTES(CONSTANT) may not be declared in a host subprogram
6363
real, constant :: rc
6464
end subroutine
65+
66+
attributes(global) subroutine devsubr2()
67+
real, shared :: rs
68+
69+
rs = 1 ! ok
70+
end subroutine
71+
6572
end module

0 commit comments

Comments
 (0)