Skip to content

Commit 9ba332f

Browse files
authored
[Flang][OpenMP] Deprecate Allocate Directive (#142378)
As part of OpenMP 5.2, the allocate directive has been deprecated in favour of the allocators construct for Fortran when an ALLOCATE statement follows the OpenMP allocate directive. To enable this in flang, a warning has been added informing the user of this. Tests to ensure this behaviour is continued are also included. See also: #110008
1 parent 2c4f677 commit 9ba332f

File tree

9 files changed

+19
-2
lines changed

9 files changed

+19
-2
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPDispatchConstruct &x) {
20732073
}
20742074

20752075
bool OmpAttributeVisitor::Pre(const parser::OpenMPExecutableAllocate &x) {
2076+
IssueNonConformanceWarning(llvm::omp::Directive::OMPD_allocate, x.source);
20762077
PushContext(x.source, llvm::omp::Directive::OMPD_allocate);
20772078
const auto &list{std::get<std::optional<parser::OmpObjectList>>(x.t)};
20782079
if (list) {
@@ -3156,6 +3157,9 @@ void OmpAttributeVisitor::IssueNonConformanceWarning(
31563157
case llvm::omp::OMPD_parallel_master_taskloop_simd:
31573158
setAlternativeStr("PARALLEL_MASKED TASKLOOP SIMD");
31583159
break;
3160+
case llvm::omp::OMPD_allocate:
3161+
setAlternativeStr("ALLOCATORS");
3162+
break;
31593163
case llvm::omp::OMPD_target_loop:
31603164
default:;
31613165
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
! This test checks lowering of OpenMP allocate Directive.
22

3-
// RUN: not flang -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
3+
! RUN: not flang -fc1 -emit-fir -fopenmp %s 2>&1 | FileCheck %s
44

55
program main
66
integer :: x, y
77

8-
// CHECK: not yet implemented: OpenMPDeclarativeAllocate
8+
! CHECK: not yet implemented: OpenMPDeclarativeAllocate
99
!$omp allocate(x, y)
1010
end

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ program allocate_align_tree
1313
z = 3
1414
!ERROR: The alignment value should be a constant positive integer
1515
!$omp allocate(j) align(xx)
16+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1617
!ERROR: The alignment value should be a constant positive integer
1718
!$omp allocate(xarray) align(-32) allocator(omp_large_cap_mem_alloc)
1819
allocate(j(z), xarray(t))

flang/test/Semantics/OpenMP/allocate01.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ subroutine sema()
1919
!$omp allocate(y)
2020
print *, a
2121

22+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2223
!ERROR: List items must be declared in the same scoping unit in which the ALLOCATE directive appears
2324
!$omp allocate(x) allocator(omp_default_mem_alloc)
2425
allocate ( x(a), darray(a, b) )

flang/test/Semantics/OpenMP/allocate02.f90

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

19+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1920
!$omp allocate(darray) allocator(omp_default_mem_alloc)
2021
allocate ( darray(a, b) )
2122

23+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2224
!ERROR: At most one ALLOCATOR clause can appear on the ALLOCATE directive
2325
!$omp allocate(darray) allocator(omp_default_mem_alloc) allocator(omp_default_mem_alloc)
2426
allocate ( darray(a, b) )

flang/test/Semantics/OpenMP/allocate03.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ subroutine allocate()
1818
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear on the ALLOCATE directive
1919
!$omp allocate(my_var%array)
2020

21+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2122
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear on the ALLOCATE directive
2223
!$omp allocate(darray, my_var%array) allocator(omp_default_mem_alloc)
2324
allocate ( darray(a, b) )

flang/test/Semantics/OpenMP/allocate05.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ subroutine allocate()
1313
real, dimension (:,:), allocatable :: darray
1414

1515
!$omp target
16+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1617
!$omp allocate allocator(omp_default_mem_alloc)
1718
allocate ( darray(a, b) )
1819
!$omp end target
1920

2021
!$omp target
22+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2123
!ERROR: ALLOCATE directives that appear in a TARGET region must specify an allocator clause
2224
!$omp allocate
2325
allocate ( darray(a, b) )

flang/test/Semantics/OpenMP/allocate06.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ subroutine allocate()
1414
!ERROR: List items specified in the ALLOCATE directive must not have the ALLOCATABLE attribute unless the directive is associated with an ALLOCATE statement
1515
!$omp allocate(darray) allocator(omp_default_mem_alloc)
1616

17+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1718
!$omp allocate(darray) allocator(omp_default_mem_alloc)
1819
allocate(darray(a, b))
1920

flang/test/Semantics/OpenMP/allocate09.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@ subroutine allocate()
1212
integer, dimension(:), allocatable :: a, b, c, d, e, f, &
1313
g, h, i, j, k, l
1414

15+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1516
!$omp allocate(a) allocator(omp_default_mem_alloc)
1617
allocate(a(1), b(2))
1718

19+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1820
!$omp allocate(c, d) allocator(omp_default_mem_alloc)
1921
allocate(c(3), d(4))
2022

2123
!$omp allocate(e) allocator(omp_default_mem_alloc)
2224
!$omp allocate(f, g) allocator(omp_default_mem_alloc)
25+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2326
!$omp allocate
2427
allocate(e(5), f(6), g(7))
2528

29+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2630
!ERROR: Object 'i' in ALLOCATE directive not found in corresponding ALLOCATE statement
2731
!$omp allocate(h, i) allocator(omp_default_mem_alloc)
2832
allocate(h(8))
2933

3034
!ERROR: Object 'j' in ALLOCATE directive not found in corresponding ALLOCATE statement
3135
!$omp allocate(j, k) allocator(omp_default_mem_alloc)
36+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3237
!$omp allocate(l) allocator(omp_default_mem_alloc)
3338
allocate(k(9), l(10))
3439

0 commit comments

Comments
 (0)