Skip to content

[flang][cuda] Allow STOP in device context #120625

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 3 commits into from
Dec 19, 2024
Merged

Conversation

clementval
Copy link
Contributor

STOP statement is allowed in device procedure

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

llvmbot commented Dec 19, 2024

@llvm/pr-subscribers-flang-semantics

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

Changes

STOP statement is allowed in device procedure


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-cuda.cpp (+7)
  • (modified) flang/test/Semantics/cuf09.cuf (+5)
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index bec3969c7a26b7..ba519a4f37d308 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -82,6 +82,10 @@ struct DeviceExprChecker
           }
         }
       }
+      // c_devloc is inlined in lowering.
+      if (x.GetName().compare("c_devloc") == 0) {
+        return {};
+      }
     } else if (x.GetSpecificIntrinsic()) {
       // TODO(CUDA): Check for unsupported intrinsics here
       return {};
@@ -350,6 +354,9 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
   void Check(const parser::ActionStmt &stmt, const parser::CharBlock &source) {
     common::visit(
         common::visitors{
+            [&](const common::Indirection<parser::StopStmt> &) {
+              return;
+            },
             [&](const common::Indirection<parser::PrintStmt> &) {},
             [&](const common::Indirection<parser::WriteStmt> &x) {
               if (x.value().format) { // Formatted write to '*' or '6'
diff --git a/flang/test/Semantics/cuf09.cuf b/flang/test/Semantics/cuf09.cuf
index b45ca6d7d1a9d7..3307e2a8626729 100644
--- a/flang/test/Semantics/cuf09.cuf
+++ b/flang/test/Semantics/cuf09.cuf
@@ -49,6 +49,11 @@ module m
     i = threadIdx%x
     a(i) = c(10) ! ok, a is device and c is constant
   end subroutine
+
+  attributes(global) subroutine stoptest()
+    print*,threadIdx%x
+    stop ! ok
+  end subroutine
 end
 
 program main

Copy link

github-actions bot commented Dec 19, 2024

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

@clementval clementval merged commit 7009b06 into llvm:main Dec 19, 2024
5 of 7 checks passed
@clementval clementval deleted the cuf_stop branch December 19, 2024 20:41
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