Skip to content

Commit 9ac5b1f

Browse files
[flang][openmp] Semantic check for OpenMPExecutableAllocate
Executable allocate directives require that list items show up in the corresponding allocate statement. This patch is dependent on revision D150428 and applies the semantic check introduced there to allocate directives associated with allocate statements. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D150483
1 parent af9dafe commit 9ac5b1f

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,21 @@ void OmpAttributeVisitor::Post(const parser::OpenMPExecutableAllocate &x) {
17611761
"ALLOCATE directives that appear in a TARGET region "
17621762
"must specify an allocator clause"_err_en_US);
17631763
}
1764+
1765+
const auto &allocateStmt =
1766+
std::get<parser::Statement<parser::AllocateStmt>>(x.t).statement;
1767+
if (const auto &list{std::get<std::optional<parser::OmpObjectList>>(x.t)}) {
1768+
CheckAllNamesInAllocateStmt(
1769+
std::get<parser::Verbatim>(x.t).source, *list, allocateStmt);
1770+
}
1771+
if (const auto &subDirs{
1772+
std::get<std::optional<std::list<parser::OpenMPDeclarativeAllocate>>>(
1773+
x.t)}) {
1774+
for (const auto &dalloc : *subDirs) {
1775+
CheckAllNamesInAllocateStmt(std::get<parser::Verbatim>(dalloc.t).source,
1776+
std::get<parser::OmpObjectList>(dalloc.t), allocateStmt);
1777+
}
1778+
}
17641779
PopContext();
17651780
}
17661781

flang/test/Semantics/OpenMP/allocate-directive.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
! 2.11.3 declarative allocate
66
! 2.11.3 executable allocate
77

8-
real, dimension (:,:), allocatable :: darray
9-
integer :: a, b, x, y, m, n, t, z
8+
integer :: x, y
9+
integer, allocatable :: a, b, m, n, t, z
1010
!$omp allocate(x, y)
1111
!$omp allocate(x, y) allocator(omp_default_mem_alloc)
1212

1313
!$omp allocate(a, b)
14-
allocate ( darray(a, b) )
14+
allocate ( a, b )
1515

1616
!$omp allocate(a, b) allocator(omp_default_mem_alloc)
17-
allocate ( darray(a, b) )
17+
allocate ( a, b )
1818

1919
!$omp allocate(t) allocator(omp_const_mem_alloc)
2020
!$omp allocate(z) allocator(omp_default_mem_alloc)
2121
!$omp allocate(m) allocator(omp_default_mem_alloc)
2222
!$omp allocate(n)
23-
allocate ( darray(z, t) )
23+
allocate ( t, z, m, n )
2424

2525
end

flang/test/Semantics/OpenMP/allocate01.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66

77
subroutine allocate()
88
use omp_lib
9-
integer :: x
9+
integer, allocatable :: x(:)
10+
integer :: y
1011
contains
1112
subroutine sema()
1213
integer :: a, b
1314
real, dimension (:,:), allocatable :: darray
1415

1516
!ERROR: List items must be declared in the same scoping unit in which the ALLOCATE directive appears
16-
!$omp allocate(x)
17+
!$omp allocate(y)
1718
print *, a
1819

1920
!ERROR: List items must be declared in the same scoping unit in which the ALLOCATE directive appears
2021
!$omp allocate(x) allocator(omp_default_mem_alloc)
21-
allocate ( darray(a, b) )
22+
allocate ( x(a), darray(a, b) )
2223
end subroutine sema
2324

2425
end subroutine allocate

flang/test/Semantics/OpenMP/allocate02.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ subroutine allocate()
1414
!ERROR: At most one ALLOCATOR clause can appear on the ALLOCATE directive
1515
!$omp allocate(x, y) allocator(omp_default_mem_alloc) allocator(omp_default_mem_alloc)
1616

17-
!$omp allocate(x) allocator(omp_default_mem_alloc)
17+
!$omp allocate(darray) allocator(omp_default_mem_alloc)
1818
allocate ( darray(a, b) )
1919

2020
!ERROR: At most one ALLOCATOR clause can appear on the ALLOCATE directive
21-
!$omp allocate(x) allocator(omp_default_mem_alloc) allocator(omp_default_mem_alloc)
21+
!$omp allocate(darray) allocator(omp_default_mem_alloc) allocator(omp_default_mem_alloc)
2222
allocate ( darray(a, b) )
2323

2424
end subroutine allocate
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
! OpenMP Version 5.0
3+
! 2.11.3 allocate Directive
4+
! List items specified in an allocate directive that is associated
5+
! with an allocate statement must be variables that are allocated
6+
! by the allocate statement.
7+
8+
subroutine allocate()
9+
use omp_lib
10+
integer, dimension(:), allocatable :: a, b, c, d, e, f, &
11+
g, h, i, j, k, l
12+
13+
!$omp allocate(a) allocator(omp_default_mem_alloc)
14+
allocate(a(1), b(2))
15+
16+
!$omp allocate(c, d) allocator(omp_default_mem_alloc)
17+
allocate(c(3), d(4))
18+
19+
!$omp allocate(e) allocator(omp_default_mem_alloc)
20+
!$omp allocate(f, g) allocator(omp_default_mem_alloc)
21+
!$omp allocate
22+
allocate(e(5), f(6), g(7))
23+
24+
!ERROR: Object 'i' in ALLOCATE directive not found in corresponding ALLOCATE statement
25+
!$omp allocate(h, i) allocator(omp_default_mem_alloc)
26+
allocate(h(8))
27+
28+
!ERROR: Object 'j' in ALLOCATE directive not found in corresponding ALLOCATE statement
29+
!$omp allocate(j, k) allocator(omp_default_mem_alloc)
30+
!$omp allocate(l) allocator(omp_default_mem_alloc)
31+
allocate(k(9), l(10))
32+
33+
end subroutine allocate

0 commit comments

Comments
 (0)