Skip to content

Commit 7c555cb

Browse files
authored
[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).
1 parent 265953c commit 7c555cb

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,13 @@ void CheckHelper::CheckSubprogram(
14701470
messages_.Say(symbol.name(),
14711471
"A function may not have ATTRIBUTES(GLOBAL) or ATTRIBUTES(GRID_GLOBAL)"_err_en_US);
14721472
}
1473+
if (cudaAttrs &&
1474+
(*cudaAttrs == common::CUDASubprogramAttrs::Global ||
1475+
*cudaAttrs == common::CUDASubprogramAttrs::Grid_Global) &&
1476+
symbol.attrs().HasAny({Attr::RECURSIVE, Attr::PURE, Attr::ELEMENTAL})) {
1477+
messages_.Say(symbol.name(),
1478+
"A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL"_err_en_US);
1479+
}
14731480
if (cudaAttrs && *cudaAttrs != common::CUDASubprogramAttrs::Host) {
14741481
// CUDA device subprogram checks
14751482
if (ClassifyProcedure(symbol) == ProcedureDefinitionClass::Internal) {

flang/test/Semantics/cuf02.cuf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,23 @@ module m
2929
!ERROR: A function may not have ATTRIBUTES(GLOBAL) or ATTRIBUTES(GRID_GLOBAL)
3030
attributes(global) real function f1
3131
end
32-
recursive attributes(global) subroutine s7 ! ok
32+
!ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
33+
recursive attributes(global) subroutine s7
3334
end
34-
pure attributes(global) subroutine s8 ! ok
35+
!ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
36+
pure attributes(global) subroutine s8
3537
end
36-
elemental attributes(global) subroutine s9 ! ok
38+
!ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
39+
elemental attributes(global) subroutine s9
40+
end
41+
!ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
42+
recursive attributes(grid_global) subroutine s10
43+
end
44+
!ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
45+
pure attributes(grid_global) subroutine s11
46+
end
47+
!ERROR: A kernel subprogram may not be RECURSIVE, PURE, or ELEMENTAL
48+
elemental attributes(grid_global) subroutine s12
3749
end
3850
end
3951

0 commit comments

Comments
 (0)