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] Allow if stmt in device subroutine #89347

Merged
merged 2 commits into from
Apr 19, 2024

Conversation

clementval
Copy link
Contributor

No description provided.

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

llvmbot commented Apr 19, 2024

@llvm/pr-subscribers-flang-semantics

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

Changes

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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-cuda.cpp (+9)
  • (modified) flang/test/Semantics/cuf11.cuf (+4)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index fb1ebadd378586..397fdc49196487 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -344,6 +344,9 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
             [&](const common::Indirection<parser::BackspaceStmt> &x) {
               WarnOnIoStmt(source);
             },
+            [&](const common::Indirection<parser::IfStmt> &x) {
+              Check(x.value());
+            },
             [&](const auto &x) {
               if (auto msg{ActionStmtChecker<IsCUFKernelDo>::WhyNotOk(x)}) {
                 context_.Say(source, std::move(*msg));
@@ -369,6 +372,12 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
       Check(std::get<parser::Block>(eb->t));
     }
   }
+  void Check(const parser::IfStmt &is) {
+    const auto &uS{std::get<parser::UnlabeledStatement<parser::ActionStmt>>(is.t)};
+    CheckUnwrappedExpr(context_, uS.source,
+        std::get<parser::ScalarLogicalExpr>(is.t));
+    Check(uS.statement, uS.source);
+  }
   void Check(const parser::LoopControl::Bounds &bounds) {
     Check(bounds.lower);
     Check(bounds.upper);
diff --git a/flang/test/Semantics/cuf11.cuf b/flang/test/Semantics/cuf11.cuf
index de7ff29743242b..554ac258e55101 100644
--- a/flang/test/Semantics/cuf11.cuf
+++ b/flang/test/Semantics/cuf11.cuf
@@ -30,3 +30,7 @@ logical function compare_h(a,b)
 !ERROR: 'b' is not an object of derived type; it is implicitly typed
   compare_h = (a%h .eq. b%h)
 end
+
+attributes(global) subroutine sub2()
+  if (threadIdx%x == 1) print *, "I'm number one"
+end subroutine

Copy link

github-actions bot commented Apr 19, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@clementval clementval merged commit a309c07 into llvm:main Apr 19, 2024
3 of 4 checks passed
@clementval clementval deleted the cuda_ifstmt branch April 19, 2024 14:30
aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 21, 2024
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