From 5c90527b436d1c7d753c187aff1b45e6c8da1af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Clement=20=28=E3=83=90=E3=83=AC=E3=83=B3?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=B3=20=E3=82=AF=E3=83=AC=E3=83=A1?= =?UTF-8?q?=E3=83=B3=29?= Date: Fri, 23 Feb 2024 12:56:41 -0800 Subject: [PATCH] [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 --- flang/lib/Semantics/definable.cpp | 5 +++-- flang/test/Semantics/cuf03.cuf | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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 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