[flang-commits] [flang] [flang][cuda] Accept variable with UNIFIED attribute in main (PR #90647)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Tue Apr 30 11:50:00 PDT 2024


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

UNIFIED variable are accept in program scope. Update the check to allow them. 

>From e638e01c800cebed51d4153fc3060e4ce0cc7eb5 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Tue, 30 Apr 2024 11:48:33 -0700
Subject: [PATCH] [flang][cuda] Accept variable with UNIFIED attribute in main

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

diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 901ac20f8aae9b..d49c8e059591c2 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -984,7 +984,10 @@ void CheckHelper::CheckObjectEntity(
       }
       break;
     case common::CUDADataAttr::Unified:
-      if ((!subpDetails || inDeviceSubprogram) && !isComponent) {
+      if (((!subpDetails &&
+               symbol.owner().kind() != Scope::Kind::MainProgram) ||
+              inDeviceSubprogram) &&
+          !isComponent) {
         messages_.Say(
             "Object '%s' with ATTRIBUTES(UNIFIED) must be declared in a host subprogram"_err_en_US,
             symbol.name());
diff --git a/flang/test/Semantics/cuf03.cuf b/flang/test/Semantics/cuf03.cuf
index 472d53db7462ae..a98dd60cdb8a4e 100644
--- a/flang/test/Semantics/cuf03.cuf
+++ b/flang/test/Semantics/cuf03.cuf
@@ -89,3 +89,7 @@ module m
 
 
 end module
+
+program p
+  real, unified :: um ! ok
+end program



More information about the flang-commits mailing list