Skip to content

Commit 7844f5e

Browse files
committed
[Flang] [Semantics] [OpenMP] Add semantic checks for ALLOCATE
directive.
1 parent 7915124 commit 7844f5e

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,10 +1708,33 @@ void OmpStructureChecker::CheckAlignValue(const parser::OmpClause &clause) {
17081708

17091709
void OmpStructureChecker::Enter(const parser::OpenMPDeclarativeAllocate &x) {
17101710
isPredefinedAllocator = true;
1711+
SymbolSourceMap symbols;
17111712
const auto &dir{std::get<parser::Verbatim>(x.t)};
17121713
const auto &objectList{std::get<parser::OmpObjectList>(x.t)};
17131714
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_allocate);
17141715
const auto &clauseList{std::get<parser::OmpClauseList>(x.t)};
1716+
SymbolSourceMap currSymbols;
1717+
GetSymbolsInObjectList(objectList, currSymbols);
1718+
for (auto &[symbol, source] : currSymbols) {
1719+
if (IsPointer(*symbol)) {
1720+
context_.Say(source,
1721+
"List item '%s' in ALLOCATE directive must not have POINTER "
1722+
"attribute"_err_en_US,
1723+
source.ToString());
1724+
}
1725+
if (IsDummy(*symbol)) {
1726+
context_.Say(source,
1727+
"List item '%s' in ALLOCATE directive must not be a dummy "
1728+
"argument"_err_en_US,
1729+
source.ToString());
1730+
}
1731+
if (symbol->has<AssocEntityDetails>()) {
1732+
context_.Say(source,
1733+
"List item '%s' in ALLOCATE directive must not be an associate "
1734+
"name"_err_en_US,
1735+
source.ToString());
1736+
}
1737+
}
17151738
for (const auto &clause : clauseList.v) {
17161739
CheckAlignValue(clause);
17171740
}

flang/test/Semantics/OpenMP/allocate04.f90

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@
44
! OpenMP Version 5.0
55
! 2.11.3 allocate Directive
66
! Only the allocator clause is allowed on the allocate directive
7-
subroutine allocate()
7+
! List item in ALLOCATE directive must not be a dummy argument
8+
! List item in ALLOCATE directive must not have POINTER attribute
9+
! List item in ALLOCATE directive must not be a associate name
10+
subroutine allocate(z)
811
use omp_lib
12+
use iso_c_binding
913

10-
integer :: x, y
14+
type(c_ptr), pointer :: p
15+
integer :: x, y, z
1116

17+
associate (a => x)
1218
!$omp allocate(x) allocator(omp_default_mem_alloc)
1319

1420
!ERROR: PRIVATE clause is not allowed on the ALLOCATE directive
1521
!$omp allocate(y) private(y)
22+
!ERROR: List item 'z' in ALLOCATE directive must not be a dummy argument
23+
!$omp allocate(z)
24+
!ERROR: List item 'p' in ALLOCATE directive must not have POINTER attribute
25+
!$omp allocate(p)
26+
!ERROR: List item 'a' in ALLOCATE directive must not be an associate name
27+
!$omp allocate(a)
28+
end associate
1629
end subroutine allocate

0 commit comments

Comments
 (0)