[flang-commits] [flang] 7c555cb - [flang][cuda] Reapply restriction on kernel subprogram but not device (#91764)
via flang-commits
flang-commits at lists.llvm.org
Fri May 10 10:47:08 PDT 2024
Author: Valentin Clement (バレンタイン クレメン)
Date: 2024-05-10T10:47:04-07:00
New Revision: 7c555cb2349b7f5f3b8336c40f38965aca354472
URL: https://github.com/llvm/llvm-project/commit/7c555cb2349b7f5f3b8336c40f38965aca354472
DIFF: https://github.com/llvm/llvm-project/commit/7c555cb2349b7f5f3b8336c40f38965aca354472.diff
LOG: [flang][cuda] Reapply restriction on kernel subprogram but not device (#91764)
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).
Added:
Modified:
flang/lib/Semantics/check-declarations.cpp
flang/test/Semantics/cuf02.cuf
Removed:
################################################################################
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
More information about the flang-commits
mailing list