Skip to content

[Flang][OpenMP] Deprecate Allocate Directive #142378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,6 +2035,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPDispatchConstruct &x) {
}

bool OmpAttributeVisitor::Pre(const parser::OpenMPExecutableAllocate &x) {
IssueNonConformanceWarning(llvm::omp::Directive::OMPD_allocate, x.source);
PushContext(x.source, llvm::omp::Directive::OMPD_allocate);
const auto &list{std::get<std::optional<parser::OmpObjectList>>(x.t)};
if (list) {
Expand Down Expand Up @@ -3074,6 +3075,9 @@ void OmpAttributeVisitor::IssueNonConformanceWarning(
case llvm::omp::OMPD_parallel_master_taskloop_simd:
setAlternativeStr("PARALLEL_MASKED TASKLOOP SIMD");
break;
case llvm::omp::OMPD_allocate:
setAlternativeStr("ALLOCATORS");
break;
case llvm::omp::OMPD_target_loop:
default:;
}
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Lower/OpenMP/Todo/omp-declarative-allocate.f90
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
! This test checks lowering of OpenMP allocate Directive.

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

program main
integer :: x, y

// CHECK: not yet implemented: OpenMPDeclarativeAllocate
! CHECK: not yet implemented: OpenMPDeclarativeAllocate
!$omp allocate(x, y)
end
1 change: 1 addition & 0 deletions flang/test/Semantics/OpenMP/allocate-align01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ program allocate_align_tree
z = 3
!ERROR: The alignment value should be a constant positive integer
!$omp allocate(j) align(xx)
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
!ERROR: The alignment value should be a constant positive integer
!$omp allocate(xarray) align(-32) allocator(omp_large_cap_mem_alloc)
allocate(j(z), xarray(t))
Expand Down
1 change: 1 addition & 0 deletions flang/test/Semantics/OpenMP/allocate01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ subroutine sema()
!$omp allocate(y)
print *, a

!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
!ERROR: List items must be declared in the same scoping unit in which the ALLOCATE directive appears
!$omp allocate(x) allocator(omp_default_mem_alloc)
allocate ( x(a), darray(a, b) )
Expand Down
2 changes: 2 additions & 0 deletions flang/test/Semantics/OpenMP/allocate02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ subroutine allocate()
!ERROR: At most one ALLOCATOR clause can appear on the ALLOCATE directive
!$omp allocate(x, y) allocator(omp_default_mem_alloc) allocator(omp_default_mem_alloc)

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

!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
!ERROR: At most one ALLOCATOR clause can appear on the ALLOCATE directive
!$omp allocate(darray) allocator(omp_default_mem_alloc) allocator(omp_default_mem_alloc)
allocate ( darray(a, b) )
Expand Down
1 change: 1 addition & 0 deletions flang/test/Semantics/OpenMP/allocate03.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ subroutine allocate()
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear on the ALLOCATE directive
!$omp allocate(my_var%array)

!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear on the ALLOCATE directive
!$omp allocate(darray, my_var%array) allocator(omp_default_mem_alloc)
allocate ( darray(a, b) )
Expand Down
2 changes: 2 additions & 0 deletions flang/test/Semantics/OpenMP/allocate05.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ subroutine allocate()
real, dimension (:,:), allocatable :: darray

!$omp target
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
!$omp allocate allocator(omp_default_mem_alloc)
allocate ( darray(a, b) )
!$omp end target

!$omp target
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
!ERROR: ALLOCATE directives that appear in a TARGET region must specify an allocator clause
!$omp allocate
allocate ( darray(a, b) )
Expand Down
1 change: 1 addition & 0 deletions flang/test/Semantics/OpenMP/allocate06.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ subroutine allocate()
!ERROR: List items specified in the ALLOCATE directive must not have the ALLOCATABLE attribute unless the directive is associated with an ALLOCATE statement
!$omp allocate(darray) allocator(omp_default_mem_alloc)

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

Expand Down
5 changes: 5 additions & 0 deletions flang/test/Semantics/OpenMP/allocate09.f90
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@ subroutine allocate()
integer, dimension(:), allocatable :: a, b, c, d, e, f, &
g, h, i, j, k, l

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

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

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

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

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

Expand Down