[flang][cuda] Allow assumed-size declaration for SHARED variable (#130833)

Avoid triggering an assertion for shared variable using the assumed-size
syntax.

```
attributes(global) subroutine sharedstar()
  real, shared :: s(*) ! ok. dynamic shared memory.
end subroutine
```
This commit is contained in:
Valentin Clement (バレンタイン クレメン)
2025-03-13 11:06:17 -07:00
committed by GitHub
parent e93e0dd10c
commit 369da8421c
3 changed files with 22 additions and 2 deletions

View File

@@ -403,8 +403,9 @@ public:
continue;
}
} else if (subs.ubound().isStar()) {
assert(Fortran::semantics::IsNamedConstant(sym) &&
"expect implied shape constant");
assert(Fortran::semantics::IsNamedConstant(sym) ||
Fortran::semantics::IsCUDAShared(sym) &&
"expect implied shape constant");
shapes.push_back(fir::SequenceType::getUnknownExtent());
continue;
}

View File

@@ -222,6 +222,16 @@ inline bool HasCUDAAttr(const Symbol &sym) {
return false;
}
inline bool IsCUDAShared(const Symbol &sym) {
if (const auto *details{sym.GetUltimate().detailsIf<ObjectEntityDetails>()}) {
if (details->cudaDataAttr() &&
*details->cudaDataAttr() == common::CUDADataAttr::Shared) {
return true;
}
}
return false;
}
inline bool NeedCUDAAlloc(const Symbol &sym) {
if (IsDummy(sym)) {
return false;

View File

@@ -0,0 +1,9 @@
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
attributes(global) subroutine sharedstar()
real, shared :: s(*) ! ok. dynamic shared memory.
end subroutine
! CHECK-LABEL: func.func @_QPsharedstar()
! CHECK: hlfir.declare %{{.*}}(%{{.*}}) {data_attr = #cuf.cuda<shared>, uniq_name = "_QFsharedstarEs"} : (!fir.ref<!fir.array<?xf32>>, !fir.shape<1>) -> (!fir.box<!fir.array<?xf32>>, !fir.ref<!fir.array<?xf32>>)