Skip to content

Commit 6846258

Browse files
authored
[flang][OpenMP] Add semantic check for declare target (#71425)
This patch adds a semantic check for the following: ``` If a list item is a procedure name, it must not be a generic name, procedure pointer, entry name, or statement function name. ```
1 parent 0974b5f commit 6846258

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

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

+31
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,37 @@ void OmpStructureChecker::Enter(const parser::OpenMPDeclareTargetConstruct &x) {
11731173
}
11741174
}
11751175

1176+
void OmpStructureChecker::Enter(const parser::OmpDeclareTargetWithList &x) {
1177+
SymbolSourceMap symbols;
1178+
GetSymbolsInObjectList(x.v, symbols);
1179+
for (auto &[symbol, source] : symbols) {
1180+
const GenericDetails *genericDetails = symbol->detailsIf<GenericDetails>();
1181+
if (genericDetails) {
1182+
context_.Say(source,
1183+
"The procedure '%s' in DECLARE TARGET construct cannot be a generic name."_err_en_US,
1184+
symbol->name());
1185+
genericDetails->specific();
1186+
}
1187+
if (IsProcedurePointer(*symbol)) {
1188+
context_.Say(source,
1189+
"The procedure '%s' in DECLARE TARGET construct cannot be a procedure pointer."_err_en_US,
1190+
symbol->name());
1191+
}
1192+
const SubprogramDetails *entryDetails =
1193+
symbol->detailsIf<SubprogramDetails>();
1194+
if (entryDetails && entryDetails->entryScope()) {
1195+
context_.Say(source,
1196+
"The procedure '%s' in DECLARE TARGET construct cannot be an entry name."_err_en_US,
1197+
symbol->name());
1198+
}
1199+
if (IsStmtFunction(*symbol)) {
1200+
context_.Say(source,
1201+
"The procedure '%s' in DECLARE TARGET construct cannot be a statement function."_err_en_US,
1202+
symbol->name());
1203+
}
1204+
}
1205+
}
1206+
11761207
void OmpStructureChecker::CheckSymbolNames(
11771208
const parser::CharBlock &source, const parser::OmpObjectList &objList) {
11781209
for (const auto &ompObject : objList.v) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class OmpStructureChecker
7979
void Leave(const parser::OpenMPDeclarativeAllocate &);
8080
void Enter(const parser::OpenMPDeclareTargetConstruct &);
8181
void Leave(const parser::OpenMPDeclareTargetConstruct &);
82+
void Enter(const parser::OmpDeclareTargetWithList &);
8283
void Enter(const parser::OpenMPExecutableAllocate &);
8384
void Leave(const parser::OpenMPExecutableAllocate &);
8485
void Enter(const parser::OpenMPAllocatorsConstruct &);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
3+
module my_module
4+
interface foo
5+
subroutine foo_int(a)
6+
integer :: a
7+
end subroutine
8+
subroutine foo_real(a)
9+
real :: a
10+
end subroutine
11+
end interface
12+
contains
13+
subroutine bar(N)
14+
integer :: N
15+
entry entry1(N)
16+
end subroutine
17+
subroutine foobar(N)
18+
integer::N
19+
!ERROR: The procedure 'entry1' in DECLARE TARGET construct cannot be an entry name.
20+
!$omp declare target(bar, entry1)
21+
call bar(N)
22+
end subroutine
23+
end module
24+
25+
module other_mod
26+
abstract interface
27+
integer function foo(a)
28+
integer, intent(in) :: a
29+
end function
30+
end interface
31+
procedure(foo), pointer :: procptr
32+
!ERROR: The procedure 'procptr' in DECLARE TARGET construct cannot be a procedure pointer.
33+
!$omp declare target(procptr)
34+
end module
35+
36+
subroutine baz(x)
37+
real, intent(inout) :: x
38+
real :: res
39+
stmtfunc(x) = 4.0 * (x**3)
40+
!ERROR: The procedure 'stmtfunc' in DECLARE TARGET construct cannot be a statement function.
41+
!$omp declare target (stmtfunc)
42+
res = stmtfunc(x)
43+
end subroutine
44+
45+
program main
46+
use my_module
47+
!ERROR: The procedure 'foo' in DECLARE TARGET construct cannot be a generic name.
48+
!$omp declare target(foo)
49+
end

0 commit comments

Comments
 (0)