[flang-commits] [flang] [flang][cuda] Allow if stmt in device subroutine (PR #89347)

via flang-commits flang-commits at lists.llvm.org
Thu Apr 18 22:57:12 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

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

<details>
<summary>Changes</summary>



---
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
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

``````````

</details>


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


More information about the flang-commits mailing list