From 62b1f9159667efa63f86d62c419af70af000ceac Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Tue, 11 Mar 2025 13:59:54 -0700 Subject: [PATCH] [flang][cuda] Allow assumed-size declaration for SHARED variable --- flang/include/flang/Lower/BoxAnalyzer.h | 5 +++-- flang/include/flang/Semantics/tools.h | 10 ++++++++++ flang/test/Lower/CUDA/cuda-shared01.cuf | 9 +++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 flang/test/Lower/CUDA/cuda-shared01.cuf diff --git a/flang/include/flang/Lower/BoxAnalyzer.h b/flang/include/flang/Lower/BoxAnalyzer.h index 8eca7d66a71bf..cd9037360a56b 100644 --- a/flang/include/flang/Lower/BoxAnalyzer.h +++ b/flang/include/flang/Lower/BoxAnalyzer.h @@ -403,8 +403,9 @@ class BoxAnalyzer : public fir::details::matcher { 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; } diff --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h index 16fd8d158b0e0..31dfad098f3a7 100644 --- a/flang/include/flang/Semantics/tools.h +++ b/flang/include/flang/Semantics/tools.h @@ -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()}) { + if (details->cudaDataAttr() && + *details->cudaDataAttr() == common::CUDADataAttr::Shared) { + return true; + } + } + return false; +} + inline bool NeedCUDAAlloc(const Symbol &sym) { if (IsDummy(sym)) { return false; diff --git a/flang/test/Lower/CUDA/cuda-shared01.cuf b/flang/test/Lower/CUDA/cuda-shared01.cuf new file mode 100644 index 0000000000000..a4603bed1f0ed --- /dev/null +++ b/flang/test/Lower/CUDA/cuda-shared01.cuf @@ -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, uniq_name = "_QFsharedstarEs"} : (!fir.ref>, !fir.shape<1>) -> (!fir.box>, !fir.ref>)