[flang-commits] [flang] [flang][cuda] Reapply restriction on kernel subprogram but not device (PR #91764)
via flang-commits
flang-commits at lists.llvm.org
Fri May 10 09:25:30 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Valentin Clement (バレンタイン クレメン) (clementval)
<details>
<summary>Changes</summary>
The restriction was completely removed in #<!-- -->89677. This was a bit too much. Reapply the restriction on elemental, pure and recursive but only for kernel subprogram (`grid_global` and `global` attributes).
---
Full diff: https://github.com/llvm/llvm-project/pull/91764.diff
2 Files Affected:
- (modified) flang/lib/Semantics/check-declarations.cpp (+7)
- (modified) flang/test/Semantics/cuf02.cuf (+15-3)
``````````diff
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 26efa288b5aee..ce7870b8d54e4 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -1470,6 +1470,13 @@ void CheckHelper::CheckSubprogram(
messages_.Say(symbol.name(),
"A function may not have ATTRIBUTES(GLOBAL) or ATTRIBUTES(GRID_GLOBAL)"_err_en_US);
}
+ if (cudaAttrs &&
+ (*cudaAttrs == common::CUDASubprogramAttrs::Global ||
+ *cudaAttrs == common::CUDASubprogramAttrs::Grid_Global) &&
+ symbol.attrs().HasAny({Attr::RECURSIVE, Attr::PURE, Attr::ELEMENTAL})) {
+ messages_.Say(symbol.name(),
+ "A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL"_err_en_US);
+ }
if (cudaAttrs && *cudaAttrs != common::CUDASubprogramAttrs::Host) {
// CUDA device subprogram checks
if (ClassifyProcedure(symbol) == ProcedureDefinitionClass::Internal) {
diff --git a/flang/test/Semantics/cuf02.cuf b/flang/test/Semantics/cuf02.cuf
index a4a229565a3e8..58cb3cf490115 100644
--- a/flang/test/Semantics/cuf02.cuf
+++ b/flang/test/Semantics/cuf02.cuf
@@ -29,11 +29,23 @@ module m
!ERROR: A function may not have ATTRIBUTES(GLOBAL) or ATTRIBUTES(GRID_GLOBAL)
attributes(global) real function f1
end
- recursive attributes(global) subroutine s7 ! ok
+ !ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
+ recursive attributes(global) subroutine s7
end
- pure attributes(global) subroutine s8 ! ok
+ !ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
+ pure attributes(global) subroutine s8
end
- elemental attributes(global) subroutine s9 ! ok
+ !ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
+ elemental attributes(global) subroutine s9
+ end
+ !ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
+ recursive attributes(grid_global) subroutine s10
+ end
+ !ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
+ pure attributes(grid_global) subroutine s11
+ end
+ !ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
+ elemental attributes(grid_global) subroutine s12
end
end
``````````
</details>
https://github.com/llvm/llvm-project/pull/91764
More information about the flang-commits
mailing list