Skip to content

[flang][cuda] Relax semantic for device variable in block construct #89330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

clementval
Copy link
Contributor

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

@clementval clementval requested review from klausler and wangzpgi April 18, 2024 23:10
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Apr 18, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 18, 2024

@llvm/pr-subscribers-flang-semantics

Author: Valentin Clement (バレンタイン クレメン) (clementval)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/89330.diff

3 Files Affected:

  • (modified) flang/lib/Semantics/check-declarations.cpp (+3-2)
  • (modified) flang/test/Semantics/cuf03.cuf (+5)
  • (added) flang/test/Semantics/cuf12.cuf (+8)
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

@clementval clementval merged commit 3090efc into llvm:main Apr 19, 2024
@clementval clementval deleted the cuda_block branch April 19, 2024 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants