Skip to content

Commit 7ca3e88

Browse files
clementvalfrederik-h
authored andcommitted
[flang][cuda] Allow assumed-size declaration for SHARED variable (llvm#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 ```
1 parent 44a2a0d commit 7ca3e88

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

flang/include/flang/Lower/BoxAnalyzer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ class BoxAnalyzer : public fir::details::matcher<BoxAnalyzer> {
403403
continue;
404404
}
405405
} else if (subs.ubound().isStar()) {
406-
assert(Fortran::semantics::IsNamedConstant(sym) &&
407-
"expect implied shape constant");
406+
assert(Fortran::semantics::IsNamedConstant(sym) ||
407+
Fortran::semantics::IsCUDAShared(sym) &&
408+
"expect implied shape constant");
408409
shapes.push_back(fir::SequenceType::getUnknownExtent());
409410
continue;
410411
}

flang/include/flang/Semantics/tools.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,16 @@ inline bool HasCUDAAttr(const Symbol &sym) {
222222
return false;
223223
}
224224

225+
inline bool IsCUDAShared(const Symbol &sym) {
226+
if (const auto *details{sym.GetUltimate().detailsIf<ObjectEntityDetails>()}) {
227+
if (details->cudaDataAttr() &&
228+
*details->cudaDataAttr() == common::CUDADataAttr::Shared) {
229+
return true;
230+
}
231+
}
232+
return false;
233+
}
234+
225235
inline bool NeedCUDAAlloc(const Symbol &sym) {
226236
if (IsDummy(sym)) {
227237
return false;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
3+
4+
attributes(global) subroutine sharedstar()
5+
real, shared :: s(*) ! ok. dynamic shared memory.
6+
end subroutine
7+
8+
! CHECK-LABEL: func.func @_QPsharedstar()
9+
! 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>>)

0 commit comments

Comments
 (0)