Skip to content
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

[flang][cuda] Accept variable with UNIFIED attribute in main #90647

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

clementval
Copy link
Contributor

@clementval clementval commented Apr 30, 2024

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

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Apr 30, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 30, 2024

@llvm/pr-subscribers-flang-semantics

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

Changes

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


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-declarations.cpp (+4-1)
  • (modified) flang/test/Semantics/cuf03.cuf (+4)
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

@clementval clementval merged commit 1fb5083 into llvm:main Apr 30, 2024
6 of 7 checks passed
@clementval clementval deleted the cuda_unified_main branch April 30, 2024 21:11
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.

None yet

3 participants