[flang-commits] [flang] [flang][cuda] Relax semantic for device variable in block construct (PR #89330)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Thu Apr 18 16:10:25 PDT 2024


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

There is no restriction for device variable to be in a block construct. Semantic check was raising an error. This patch relax the check to allow the code in tests. 

https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/#cfref-var-attr-device-data



>From a6039a1b0816f58064db57c1faf1cc6a9293dfbe Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Thu, 18 Apr 2024 16:09:05 -0700
Subject: [PATCH] [flang][cuda] Relax semantic for device variable in block
 construct

---
 flang/lib/Semantics/check-declarations.cpp | 5 +++--
 flang/test/Semantics/cuf03.cuf             | 5 +++++
 flang/test/Semantics/cuf12.cuf             | 8 ++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)
 create mode 100644 flang/test/Semantics/cuf12.cuf

diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 824f1b6053ca39..875929e90fdd31 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1042,9 +1042,10 @@ void CheckHelper::CheckObjectEntity(
             parser::ToUpperCaseLetters(common::EnumToString(attr)));
       }
     } else if (!subpDetails && symbol.owner().kind() != Scope::Kind::Module &&
-        symbol.owner().kind() != Scope::Kind::MainProgram) {
+        symbol.owner().kind() != Scope::Kind::MainProgram &&
+        symbol.owner().kind() != Scope::Kind::BlockConstruct) {
       messages_.Say(
-          "ATTRIBUTES(%s) may apply only to module, host subprogram, or device subprogram data"_err_en_US,
+          "ATTRIBUTES(%s) may apply only to module, host subprogram, block, or device subprogram data"_err_en_US,
           parser::ToUpperCaseLetters(common::EnumToString(attr)));
     }
   }
diff --git a/flang/test/Semantics/cuf03.cuf b/flang/test/Semantics/cuf03.cuf
index 574add9faaade7..8decb8dcaa0f47 100644
--- a/flang/test/Semantics/cuf03.cuf
+++ b/flang/test/Semantics/cuf03.cuf
@@ -85,6 +85,11 @@ module m
     real, unified :: ru ! ok
     type(t1), unified :: tu ! ok
     type(t2) :: t ! ok
+
+    block
+      real, device :: a(100) ! ok
+    end block
   end subroutine
 
+
 end module
diff --git a/flang/test/Semantics/cuf12.cuf b/flang/test/Semantics/cuf12.cuf
new file mode 100644
index 00000000000000..1b79c9889dfeaf
--- /dev/null
+++ b/flang/test/Semantics/cuf12.cuf
@@ -0,0 +1,8 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+program test
+  real, device :: b(100) ! ok
+  block
+    real, device :: a(100) ! ok
+  end block
+end program



More information about the flang-commits mailing list