Skip to content

Commit 739a5a4

Browse files
authored
[Flang][OpenMP] Fix defaultmap(none) being overly aggressive with symbol checks (#167806)
Currently we're picking up and complaining about builtin (and procedure) symbols like null() when defaultmap(none) is set, so I've relaxed the restriction a bit to allow for procedures and named constants to bypass the restriction. It might be the case that we want to tighten it up again in certain aspects in the future.
1 parent ebc0e07 commit 739a5a4

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,8 +3054,13 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
30543054
// place for the types specified.
30553055
if (Symbol * found{currScope().FindSymbol(name.source)}) {
30563056
// If the variable has declare target applied to it (enter or link) it
3057-
// is exempt from defaultmap(none) restrictions
3058-
if (!symbol->GetUltimate().test(Symbol::Flag::OmpDeclareTarget)) {
3057+
// is exempt from defaultmap(none) restrictions.
3058+
// We also exempt procedures and named constants from defaultmap(none)
3059+
// checking.
3060+
if (!symbol->GetUltimate().test(Symbol::Flag::OmpDeclareTarget) &&
3061+
!(IsProcedure(*symbol) &&
3062+
!semantics::IsProcedurePointer(*symbol)) &&
3063+
!IsNamedConstant(*symbol)) {
30593064
auto &dMap = GetContext().defaultMap;
30603065
for (auto defaults : dMap) {
30613066
if (defaults.second ==

flang/test/Semantics/OpenMP/defaultmap-clause-none.f90

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,40 @@ subroutine defaultmap_aggregate_none
9494
end do
9595
!$omp end target
9696
end subroutine defaultmap_aggregate_none
97+
98+
! Verify we do not catch null in defaultmap(none)
99+
subroutine defaultmap_builtin_none
100+
implicit none
101+
integer, pointer :: ptr(:)
102+
103+
!$omp target defaultmap(none) map(ptr)
104+
!CHECK-NOT: The DEFAULTMAP(NONE) clause requires that 'null' must be listed in a data-sharing attribute, data-mapping attribute, or is_device_ptr clause
105+
ptr => null()
106+
!$omp end target
107+
end subroutine defaultmap_builtin_none
108+
109+
module pro
110+
implicit none
111+
contains
112+
113+
function test_procedure() result(ret)
114+
integer :: ret
115+
ret = 1
116+
end function test_procedure
117+
118+
! Verify we do not catch a function symbol in defaultmap(none)
119+
! but do catch procedure pointers
120+
subroutine defaultmap_func_and_procedure_pointer()
121+
implicit none
122+
procedure(test_procedure), pointer :: f1
123+
integer :: i
124+
125+
f1 => test_procedure
126+
127+
!$omp target defaultmap(none) map(i)
128+
!ERROR: The DEFAULTMAP(NONE) clause requires that 'f1' must be listed in a data-sharing attribute, data-mapping attribute, or is_device_ptr clause
129+
i = f1()
130+
i = test_procedure()
131+
!$omp end target
132+
end subroutine defaultmap_func_and_procedure_pointer
133+
end module

0 commit comments

Comments
 (0)