Skip to content

Commit 27f3746

Browse files
committed
[flang][OpenMP] Add semantic checks for is_device_ptr
This patch adds the following semantic check for is_device_ptr ``` A list item that appears in an is_device_ptr clause must be a dummy argument that does not have the ALLOCATABLE, POINTER or VALUE attribute. ```
1 parent b0d5b4d commit 27f3746

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

flang/include/flang/Semantics/tools.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ inline bool IsPointer(const Symbol &symbol) {
143143
inline bool IsAllocatable(const Symbol &symbol) {
144144
return symbol.attrs().test(Attr::ALLOCATABLE);
145145
}
146+
inline bool IsValue(const Symbol &symbol) {
147+
return symbol.attrs().test(Attr::VALUE);
148+
}
146149
// IsAllocatableOrObjectPointer() may be the better choice
147150
inline bool IsAllocatableOrPointer(const Symbol &symbol) {
148151
return IsPointer(symbol) || IsAllocatable(symbol);

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,18 +2852,21 @@ void OmpStructureChecker::Enter(const parser::OmpClause::IsDevicePtr &x) {
28522852
const auto &isDevicePtrClause{
28532853
std::get<parser::OmpClause::IsDevicePtr>(itr->second->u)};
28542854
const auto &isDevicePtrList{isDevicePtrClause.v};
2855-
std::list<parser::Name> isDevicePtrNameList;
2856-
for (const auto &ompObject : isDevicePtrList.v) {
2857-
if (const auto *name{parser::Unwrap<parser::Name>(ompObject)}) {
2858-
if (name->symbol) {
2859-
if (!(IsBuiltinCPtr(*(name->symbol)))) {
2860-
context_.Say(itr->second->source,
2861-
"Variable '%s' in IS_DEVICE_PTR clause must be of type C_PTR"_err_en_US,
2862-
name->ToString());
2863-
} else {
2864-
isDevicePtrNameList.push_back(*name);
2865-
}
2866-
}
2855+
SymbolSourceMap currSymbols;
2856+
GetSymbolsInObjectList(isDevicePtrList, currSymbols);
2857+
for (auto &[symbol, source] : currSymbols) {
2858+
if (!(IsBuiltinCPtr(*symbol))) {
2859+
context_.Say(itr->second->source,
2860+
"Variable '%s' in IS_DEVICE_PTR clause must be of type C_PTR"_err_en_US,
2861+
source.ToString());
2862+
} else if (!(IsDummy(*symbol))) {
2863+
context_.Say(itr->second->source,
2864+
"Variable '%s' in IS_DEVICE_PTR clause must be a dummy argument"_err_en_US,
2865+
source.ToString());
2866+
} else if (IsAllocatableOrPointer(*symbol) || IsValue(*symbol)) {
2867+
context_.Say(itr->second->source,
2868+
"Variable '%s' in IS_DEVICE_PTR clause must be a dummy argument that does not have the ALLOCATABLE, POINTER or VALUE attribute."_err_en_US,
2869+
source.ToString());
28672870
}
28682871
}
28692872
}

flang/test/Semantics/OpenMP/target01.f90

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2-
2+
3+
subroutine foo(b)
34
use iso_c_binding
45
integer :: x,y
56
type(C_PTR) :: b
@@ -28,4 +29,30 @@
2829
y = y - 1
2930
!$omp end target
3031

31-
end
32+
end subroutine foo
33+
34+
subroutine bar(b1, b2, b3)
35+
use iso_c_binding
36+
integer :: y
37+
type(c_ptr) :: c
38+
type(c_ptr), allocatable :: b1
39+
type(c_ptr), pointer :: b2
40+
type(c_ptr), value :: b3
41+
42+
!ERROR: Variable 'c' in IS_DEVICE_PTR clause must be a dummy argument
43+
!$omp target is_device_ptr(c)
44+
y = y + 1
45+
!$omp end target
46+
!ERROR: Variable 'b1' in IS_DEVICE_PTR clause must be a dummy argument that does not have the ALLOCATABLE, POINTER or VALUE attribute.
47+
!$omp target is_device_ptr(b1)
48+
y = y + 1
49+
!$omp end target
50+
!ERROR: Variable 'b2' in IS_DEVICE_PTR clause must be a dummy argument that does not have the ALLOCATABLE, POINTER or VALUE attribute.
51+
!$omp target is_device_ptr(b2)
52+
y = y + 1
53+
!$omp end target
54+
!ERROR: Variable 'b3' in IS_DEVICE_PTR clause must be a dummy argument that does not have the ALLOCATABLE, POINTER or VALUE attribute.
55+
!$omp target is_device_ptr(b3)
56+
y = y + 1
57+
!$omp end target
58+
end subroutine bar

0 commit comments

Comments
 (0)