[flang-commits] [flang] [flang][cuda] Do not check dummy in stmt function in device code (PR #212037)

via flang-commits flang-commits at lists.llvm.org
Sat Jul 25 09:54:25 PDT 2026


llvmorg-github-actions[bot] 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/212037.diff


4 Files Affected:

- (modified) flang/include/flang/Evaluate/characteristics.h (+3) 
- (modified) flang/lib/Evaluate/characteristics.cpp (+1) 
- (modified) flang/lib/Semantics/check-call.cpp (+3-2) 
- (modified) flang/test/Semantics/CUDA/cuf02.cuf (+11) 


``````````diff
diff --git a/flang/include/flang/Evaluate/characteristics.h b/flang/include/flang/Evaluate/characteristics.h
index bc37f3d39c2ec..1ba0bf693c763 100644
--- a/flang/include/flang/Evaluate/characteristics.h
+++ b/flang/include/flang/Evaluate/characteristics.h
@@ -420,6 +420,9 @@ struct Procedure {
   std::optional<common::CUDASubprogramAttrs> cudaSubprogramAttrs;
   // Used only by CUDA semantic checks; this is not a CUDA procedure attribute.
   bool hasOpenACCRoutine{false};
+  // Statement functions are inlined; CUDA data-attribute matching does not
+  // apply to their dummy arguments.
+  bool isStmtFunction{false};
 };
 
 } // namespace Fortran::evaluate::characteristics
diff --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index 8750cd3c3ebb6..4b05a25fd8f58 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -669,6 +669,7 @@ static std::optional<Procedure> CharacterizeProcedure(
             }
             result.cudaSubprogramAttrs = subp.cudaSubprogramAttrs();
             result.hasOpenACCRoutine = !subp.openACCRoutineInfos().empty();
+            result.isStmtFunction = subp.stmtFunction().has_value();
             return std::move(result);
           },
           [&](const semantics::ProcEntityDetails &proc)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 0680a48bac2be..6309b3617f84b 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1125,8 +1125,9 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
 
   // CUDA specific checks
   // TODO: These are disabled in OpenACC constructs, which may not be
-  // correct when the target is not a GPU.
-  if (!intrinsic &&
+  // correct when the target is not a GPU. Statement functions are inlined
+  // during lowering, so CUDA data attributes do not apply to their dummies.
+  if (!intrinsic && !procedure.isStmtFunction &&
       !dummy.attrs.test(characteristics::DummyDataObject::Attr::Value) &&
       !FindOpenACCConstructContaining(scope)) {
     std::optional<common::CUDADataAttr> actualDataAttr, dummyDataAttr;
diff --git a/flang/test/Semantics/CUDA/cuf02.cuf b/flang/test/Semantics/CUDA/cuf02.cuf
index ac230069cf16f..9a01a693f16e7 100644
--- a/flang/test/Semantics/CUDA/cuf02.cuf
+++ b/flang/test/Semantics/CUDA/cuf02.cuf
@@ -27,6 +27,17 @@ module m
     stmtfunc(x) = x + 1. ! ok
     x = stmtfunc(x) ! ok
   end
+  attributes(device) real function s6_declared(x)
+    implicit none
+    integer i, n
+    real conv, x, y
+    ! Explicitly declared locals get ATTRIBUTES(DEVICE); statement functions
+    ! are inlined, so CUDA data-attribute matching must not apply to dummies.
+    conv(i) = real(i)
+    n = 0
+    y = x - conv(n) ! ok
+    s6_declared = y
+  end
   attributes(device) subroutine s6_bad
     badstmt(x) = hostfunc(x)
     !ERROR: 'hostfunc' may not be called in device code

``````````

</details>


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


More information about the flang-commits mailing list