[flang-commits] [flang] [flang][cuda] Allow POINTER component to have device attribute (PR #126116)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Thu Feb 6 11:28:15 PST 2025


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/126116

None

>From 7a4096184f966db87b722c710c8c0e6090021593 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 6 Feb 2025 11:27:22 -0800
Subject: [PATCH] [flang][cuda] Allow POINTER component to have device
 attribute

---
 flang/lib/Semantics/check-declarations.cpp | 4 ++--
 flang/test/Semantics/cuf03.cuf             | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 5c26469b9fa2482..bf4dc16a15b4a24 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -989,9 +989,9 @@ void CheckHelper::CheckObjectEntity(
       }
       break;
     case common::CUDADataAttr::Device:
-      if (isComponent && !IsAllocatable(symbol)) {
+      if (isComponent && !IsAllocatable(symbol) && !IsPointer(symbol)) {
         messages_.Say(
-            "Component '%s' with ATTRIBUTES(DEVICE) must also be allocatable"_err_en_US,
+            "Component '%s' with ATTRIBUTES(DEVICE) must also be allocatable or pointer"_err_en_US,
             symbol.name());
       }
       break;
diff --git a/flang/test/Semantics/cuf03.cuf b/flang/test/Semantics/cuf03.cuf
index 93b136ad7d3157c..fe9dd5b3ecf05b5 100644
--- a/flang/test/Semantics/cuf03.cuf
+++ b/flang/test/Semantics/cuf03.cuf
@@ -54,6 +54,14 @@ module m
   !ERROR: Object 'um' with ATTRIBUTES(UNIFIED) must be declared in a host subprogram
   real, unified :: um
 
+  type :: t3
+  !ERROR: Component 'r' with ATTRIBUTES(DEVICE) must also be allocatable or pointer
+    real, device :: r
+    real, device, pointer :: rp ! ok
+    real, device, allocatable :: ra ! ok
+    real, device, pointer, contiguous :: rpc ! ok
+  end type
+
  contains
   attributes(device) subroutine devsubr(n,da,rs)
     integer, intent(in) :: n



More information about the flang-commits mailing list