[flang-commits] [flang] cd0b558 - [flang][cuda][openacc] use the ultimate symbol to set the implicit device attribute (#192553)

via flang-commits flang-commits at lists.llvm.org
Fri Apr 17 10:48:55 PDT 2026


Author: Valentin Clement (バレンタイン クレメン)
Date: 2026-04-17T10:48:50-07:00
New Revision: cd0b558c195bd4d13aa311f081722fea51459a47

URL: https://github.com/llvm/llvm-project/commit/cd0b558c195bd4d13aa311f081722fea51459a47
DIFF: https://github.com/llvm/llvm-project/commit/cd0b558c195bd4d13aa311f081722fea51459a47.diff

LOG: [flang][cuda][openacc] use the ultimate symbol to set the implicit device attribute (#192553)

The attribute was not applied when the symbol had a UseDetails. Use the
ultimate symbol so we get the proper ObjectEntityDetails to apply the
implicit attribute.

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Lower/OpenACC/acc-host-data-cuda-device.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index e1c1167af1604..4f824ef1321e9 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -1511,9 +1511,9 @@ void AccVisitor::CopySymbolWithDevice(const parser::Name *name) {
   // attribute.
   if (context_.languageFeatures().IsEnabled(common::LanguageFeature::CUDA) &&
       name && name->symbol) {
-    if (Symbol * copy{currScope().CopySymbol(*name->symbol)}) {
+    if (Symbol * copy{currScope().CopySymbol(name->symbol->GetUltimate())}) {
       name->symbol = copy;
-      if (auto *object{copy->detailsIf<ObjectEntityDetails>()}) {
+      if (auto *object{copy->GetUltimate().detailsIf<ObjectEntityDetails>()}) {
         object->set_cudaDataAttr(common::CUDADataAttr::Device);
       }
     }

diff  --git a/flang/test/Lower/OpenACC/acc-host-data-cuda-device.f90 b/flang/test/Lower/OpenACC/acc-host-data-cuda-device.f90
index cc301617444ac..7bf9a6261bd58 100644
--- a/flang/test/Lower/OpenACC/acc-host-data-cuda-device.f90
+++ b/flang/test/Lower/OpenACC/acc-host-data-cuda-device.f90
@@ -3,6 +3,8 @@
 
 module m
 
+real, allocatable, pinned :: pinned_real(:,:,:)
+
 interface doit
 subroutine __device_sub(a)
     real(4), device, intent(in) :: a(:,:,:)
@@ -78,3 +80,16 @@ program testex1
 ! CHECK: fir.call @_QP__host_sub
 ! CHECK: fir.call @_QP__device_sub
 ! CHECK: fir.call @_QP__device_sub
+
+subroutine test_use_details()
+  use m
+  call doit(pinned_real)
+  !$acc host_data use_device(pinned_real)
+  call doit(pinned_real)
+  !$acc end host_data
+  call doit(pinned_real)
+end subroutine
+
+! CHECK: fir.address_of(@_QP__host_sub)
+! CHECK: fir.address_of(@_QP__device_sub)
+! CHECK: fir.address_of(@_QP__host_sub)


        


More information about the flang-commits mailing list