Skip to content

Commit

Permalink
[flang][cuda] Allow object with SHARED attribute as definable (llvm#8…
Browse files Browse the repository at this point in the history
…2822)

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
  • Loading branch information
clementval authored Feb 23, 2024
1 parent 99f31ba commit 5c90527
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flang/lib/Semantics/definable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions flang/test/Semantics/cuf03.cuf
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5c90527

Please sign in to comment.