Skip to content

Commit ccc9ab7

Browse files
committed
[Flang][OpenMP] Deprecate Allocate Directive
As part of OpenMP 5.2, the allocate directive has been deprecated in favour of the allocators construct for Fortran. 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 351f15b commit ccc9ab7

13 files changed

+49
-0
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPThreadprivate &x) {
20242024

20252025
bool OmpAttributeVisitor::Pre(const parser::OpenMPDeclarativeAllocate &x) {
20262026
PushContext(x.source, llvm::omp::Directive::OMPD_allocate);
2027+
IssueNonConformanceWarning(llvm::omp::Directive::OMPD_allocate, x.source);
20272028
const auto &list{std::get<parser::OmpObjectList>(x.t)};
20282029
ResolveOmpObjectList(list, Symbol::Flag::OmpDeclarativeAllocateDirective);
20292030
return false;
@@ -2036,6 +2037,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPDispatchConstruct &x) {
20362037

20372038
bool OmpAttributeVisitor::Pre(const parser::OpenMPExecutableAllocate &x) {
20382039
PushContext(x.source, llvm::omp::Directive::OMPD_allocate);
2040+
IssueNonConformanceWarning(llvm::omp::Directive::OMPD_allocate, x.source);
20392041
const auto &list{std::get<std::optional<parser::OmpObjectList>>(x.t)};
20402042
if (list) {
20412043
ResolveOmpObjectList(*list, Symbol::Flag::OmpExecutableAllocateDirective);
@@ -3074,6 +3076,9 @@ void OmpAttributeVisitor::IssueNonConformanceWarning(
30743076
case llvm::omp::OMPD_parallel_master_taskloop_simd:
30753077
setAlternativeStr("PARALLEL_MASKED TASKLOOP SIMD");
30763078
break;
3079+
case llvm::omp::OMPD_allocate:
3080+
setAlternativeStr("ALLOCATORS");
3081+
break;
30773082
case llvm::omp::OMPD_target_loop:
30783083
default:;
30793084
}

flang/test/Lower/OpenMP/Todo/omp-declarative-allocate-align.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
program main
66
integer :: x
77

8+
! CHECK: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
89
! CHECK: not yet implemented: OpenMPDeclarativeAllocate
910
!$omp allocate(x) align(32)
1011
end

flang/test/Lower/OpenMP/Todo/omp-declarative-allocate.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
program main
66
integer :: x, y
77

8+
// CHECK: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
89
// CHECK: not yet implemented: OpenMPDeclarativeAllocate
910
!$omp allocate(x, y)
1011
end

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ program allocate_align_tree
1111
integer :: z, t, xx
1212
t = 2
1313
z = 3
14+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1415
!ERROR: The alignment value should be a constant positive integer
1516
!$omp allocate(j) align(xx)
17+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1618
!ERROR: The alignment value should be a constant positive integer
1719
!$omp allocate(xarray) align(-32) allocator(omp_large_cap_mem_alloc)
1820
allocate(j(z), xarray(t))

flang/test/Semantics/OpenMP/allocate01.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ subroutine sema()
1515
integer :: a, b
1616
real, dimension (:,:), allocatable :: darray
1717

18+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1819
!ERROR: List items must be declared in the same scoping unit in which the ALLOCATE directive appears
1920
!$omp allocate(y)
2021
print *, a
2122

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

flang/test/Semantics/OpenMP/allocate02.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ subroutine allocate()
1111
integer :: a, b
1212
real, dimension (:,:), allocatable :: darray
1313

14+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1415
!$omp allocate(x, y) allocator(omp_default_mem_alloc)
1516

17+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1618
!ERROR: At most one ALLOCATOR clause can appear on the ALLOCATE directive
1719
!$omp allocate(x, y) allocator(omp_default_mem_alloc) allocator(omp_default_mem_alloc)
1820

21+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1922
!$omp allocate(darray) allocator(omp_default_mem_alloc)
2023
allocate ( darray(a, b) )
2124

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

flang/test/Semantics/OpenMP/allocate03.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ subroutine allocate()
1515
real, dimension (:,:), allocatable :: darray
1616
integer :: a, b
1717

18+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1819
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear on the ALLOCATE directive
1920
!$omp allocate(my_var%array)
2021

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

flang/test/Semantics/OpenMP/allocate04.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ subroutine allocate(z)
1515
integer :: x, y, z
1616

1717
associate (a => x)
18+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1819
!$omp allocate(x) allocator(omp_default_mem_alloc)
1920

21+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2022
!ERROR: PRIVATE clause is not allowed on the ALLOCATE directive
2123
!$omp allocate(y) private(y)
24+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2225
!ERROR: List item 'z' in ALLOCATE directive must not be a dummy argument
2326
!$omp allocate(z)
27+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2428
!ERROR: List item 'p' in ALLOCATE directive must not have POINTER attribute
2529
!$omp allocate(p)
30+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2631
!ERROR: List item 'a' in ALLOCATE directive must not be an associate name
2732
!$omp allocate(a)
2833
end associate

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ subroutine allocate()
1111
integer :: a, b, x
1212
real, dimension (:,:), allocatable :: darray
1313

14+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1415
!ERROR: List items specified in the ALLOCATE directive must not have the ALLOCATABLE attribute unless the directive is associated with an ALLOCATE statement
1516
!$omp allocate(darray) allocator(omp_default_mem_alloc)
1617

18+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1719
!$omp allocate(darray) allocator(omp_default_mem_alloc)
1820
allocate(darray(a, b))
1921

flang/test/Semantics/OpenMP/allocate07.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,23 @@ subroutine allocate()
1818
CHARACTER(LEN=32) :: w
1919
INTEGER, DIMENSION(:), ALLOCATABLE :: y
2020

21+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2122
!ERROR: A type parameter inquiry cannot appear on the ALLOCATE directive
2223
!$omp allocate(x%KIND)
2324

25+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2426
!ERROR: A type parameter inquiry cannot appear on the ALLOCATE directive
2527
!$omp allocate(w%LEN)
2628

29+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2730
!ERROR: A type parameter inquiry cannot appear on the ALLOCATE directive
2831
!$omp allocate(y%KIND)
2932

33+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3034
!ERROR: A type parameter inquiry cannot appear on the ALLOCATE directive
3135
!$omp allocate(my_var%kind_param)
3236

37+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3338
!ERROR: A type parameter inquiry cannot appear on the ALLOCATE directive
3439
!$omp allocate(my_var%len_param)
3540

flang/test/Semantics/OpenMP/allocate08.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,30 @@ subroutine allocate()
2525
trait(1)%value = default_mem_fb
2626
custom_allocator = omp_init_allocator(memspace, 1, trait)
2727

28+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2829
!$omp allocate(x) allocator(omp_default_mem_alloc)
30+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2931
!$omp allocate(y) allocator(omp_default_mem_alloc)
32+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3033
!$omp allocate(z) allocator(omp_default_mem_alloc)
3134

35+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3236
!$omp allocate(x)
37+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3338
!$omp allocate(y)
39+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3440
!$omp allocate(z)
3541

42+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3643
!$omp allocate(w) allocator(custom_allocator)
3744

45+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3846
!ERROR: If list items within the ALLOCATE directive have the SAVE attribute, are a common block name, or are declared in the scope of a module, then only predefined memory allocator parameters can be used in the allocator clause
3947
!$omp allocate(x) allocator(custom_allocator)
48+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
4049
!ERROR: If list items within the ALLOCATE directive have the SAVE attribute, are a common block name, or are declared in the scope of a module, then only predefined memory allocator parameters can be used in the allocator clause
4150
!$omp allocate(y) allocator(custom_allocator)
51+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
4252
!ERROR: If list items within the ALLOCATE directive have the SAVE attribute, are a common block name, or are declared in the scope of a module, then only predefined memory allocator parameters can be used in the allocator clause
4353
!$omp allocate(z) allocator(custom_allocator)
4454
end subroutine allocate

flang/test/Semantics/OpenMP/allocate09.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,31 @@ 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

23+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2124
!$omp allocate(e) allocator(omp_default_mem_alloc)
25+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2226
!$omp allocate(f, g) allocator(omp_default_mem_alloc)
27+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2328
!$omp allocate
2429
allocate(e(5), f(6), g(7))
2530

31+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2632
!ERROR: Object 'i' in ALLOCATE directive not found in corresponding ALLOCATE statement
2733
!$omp allocate(h, i) allocator(omp_default_mem_alloc)
2834
allocate(h(8))
2935

36+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3037
!ERROR: Object 'j' in ALLOCATE directive not found in corresponding ALLOCATE statement
3138
!$omp allocate(j, k) allocator(omp_default_mem_alloc)
39+
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
3240
!$omp allocate(l) allocator(omp_default_mem_alloc)
3341
allocate(k(9), l(10))
3442

0 commit comments

Comments
 (0)