Skip to content

Commit 671caef

Browse files
authored
[Flang][OpenMP] Update relevant warnings to emit when OMP >= v5.2 (#144492)
There has been a number of deprecation warnings that have been added to Flang, however these features are only deprecated when the OpenMP Version being used is 5.2 or later. Previously, flang did not consider the version with the warnings so would always be emitted. Flang now ensures warnings are emitted for the appropriate version of OpenMP, and tests are updated to reflect this change.
1 parent 1f34d68 commit 671caef

16 files changed

+24
-43
lines changed

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,8 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
835835

836836
void AddOmpRequiresToScope(Scope &, WithOmpDeclarative::RequiresFlags,
837837
std::optional<common::OmpMemoryOrderType>);
838-
void IssueNonConformanceWarning(
839-
llvm::omp::Directive D, parser::CharBlock source);
838+
void IssueNonConformanceWarning(llvm::omp::Directive D,
839+
parser::CharBlock source, unsigned EmitFromVersion);
840840

841841
void CreateImplicitSymbols(const Symbol *symbol);
842842

@@ -1668,7 +1668,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
16681668
}
16691669
if (beginDir.v == llvm::omp::Directive::OMPD_master ||
16701670
beginDir.v == llvm::omp::Directive::OMPD_parallel_master)
1671-
IssueNonConformanceWarning(beginDir.v, beginDir.source);
1671+
IssueNonConformanceWarning(beginDir.v, beginDir.source, 52);
16721672
ClearDataSharingAttributeObjects();
16731673
ClearPrivateDataSharingAttributeObjects();
16741674
ClearAllocateNames();
@@ -1791,7 +1791,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
17911791
beginDir.v == llvm::omp::OMPD_parallel_master_taskloop ||
17921792
beginDir.v == llvm::omp::OMPD_parallel_master_taskloop_simd ||
17931793
beginDir.v == llvm::omp::Directive::OMPD_target_loop)
1794-
IssueNonConformanceWarning(beginDir.v, beginDir.source);
1794+
IssueNonConformanceWarning(beginDir.v, beginDir.source, 52);
17951795
ClearDataSharingAttributeObjects();
17961796
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));
17971797

@@ -2108,7 +2108,8 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPDispatchConstruct &x) {
21082108
}
21092109

21102110
bool OmpAttributeVisitor::Pre(const parser::OpenMPExecutableAllocate &x) {
2111-
IssueNonConformanceWarning(llvm::omp::Directive::OMPD_allocate, x.source);
2111+
IssueNonConformanceWarning(llvm::omp::Directive::OMPD_allocate, x.source, 52);
2112+
21122113
PushContext(x.source, llvm::omp::Directive::OMPD_allocate);
21132114
const auto &list{std::get<std::optional<parser::OmpObjectList>>(x.t)};
21142115
if (list) {
@@ -3172,11 +3173,16 @@ void OmpAttributeVisitor::AddOmpRequiresToScope(Scope &scope,
31723173
} while (!scopeIter->IsGlobal());
31733174
}
31743175

3175-
void OmpAttributeVisitor::IssueNonConformanceWarning(
3176-
llvm::omp::Directive D, parser::CharBlock source) {
3176+
void OmpAttributeVisitor::IssueNonConformanceWarning(llvm::omp::Directive D,
3177+
parser::CharBlock source, unsigned EmitFromVersion) {
31773178
std::string warnStr;
31783179
llvm::raw_string_ostream warnStrOS(warnStr);
31793180
unsigned version{context_.langOptions().OpenMPVersion};
3181+
// We only want to emit the warning when the version being used has the
3182+
// directive deprecated
3183+
if (version < EmitFromVersion) {
3184+
return;
3185+
}
31803186
warnStrOS << "OpenMP directive "
31813187
<< parser::ToUpperCaseLetters(
31823188
llvm::omp::getOpenMPDirectiveName(D, version).str())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
! REQUIRES: openmp_runtime
22

3-
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=51
3+
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=52
44
! OpenMP Version 5.2
55
! The allocate clause's allocator modifier must be of type allocator_handle
66
! and the align modifier must be constant, positive integer expression

flang/test/Semantics/OpenMP/allocate01.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
! REQUIRES: openmp_runtime
22

3-
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags
3+
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags -fopenmp-version=52
44
! OpenMP Version 5.0
55
! 2.11.3 allocate Directive
66
! The allocate directive must appear in the same scope as the declarations of

flang/test/Semantics/OpenMP/allocate02.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ 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.
2019
!$omp allocate(darray) allocator(omp_default_mem_alloc)
2120
allocate ( darray(a, b) )
2221

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

flang/test/Semantics/OpenMP/allocate03.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ 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.
2221
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear on the ALLOCATE directive
2322
!$omp allocate(darray, my_var%array) allocator(omp_default_mem_alloc)
2423
allocate ( darray(a, b) )

flang/test/Semantics/OpenMP/allocate05.f90

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

1515
!$omp target
16-
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
1716
!$omp allocate allocator(omp_default_mem_alloc)
1817
allocate ( darray(a, b) )
1918
!$omp end target
2019

2120
!$omp target
22-
!WARNING: OpenMP directive ALLOCATE has been deprecated, please use ALLOCATORS instead.
2321
!ERROR: ALLOCATE directives that appear in a TARGET region must specify an allocator clause
2422
!$omp allocate
2523
allocate ( darray(a, b) )

flang/test/Semantics/OpenMP/allocate06.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ 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.
1817
!$omp allocate(darray) allocator(omp_default_mem_alloc)
1918
allocate(darray(a, b))
2019

flang/test/Semantics/OpenMP/allocate09.f90

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,23 @@ 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.
1615
!$omp allocate(a) allocator(omp_default_mem_alloc)
1716
allocate(a(1), b(2))
1817

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

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

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

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

flang/test/Semantics/OpenMP/clause-validity01.f90

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
! REQUIRES: openmp_runtime
22

3-
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags %openmp_module_flag -fopenmp-version=51
3+
! RUN: %python %S/../test_errors.py %s %flang_fc1 %openmp_flags %openmp_module_flag -fopenmp-version=52
44
use omp_lib
55
! Check OpenMP clause validity for the following directives:
66
!
@@ -502,19 +502,26 @@
502502
!$omp taskyield
503503
!$omp barrier
504504
!$omp taskwait
505+
!WARNING: SOURCE dependence type is deprecated in OpenMP v5.2
505506
!ERROR: The SINK and SOURCE dependence types can only be used with the ORDERED directive, used here in the TASKWAIT construct
506507
!$omp taskwait depend(source)
507508
! !$omp taskwait depend(sink:i-1)
508509
! !$omp target enter data map(to:arrayA) map(alloc:arrayB)
509510
! !$omp target update from(arrayA) to(arrayB)
510511
! !$omp target exit data map(from:arrayA) map(delete:arrayB)
511512
!$omp flush (c)
513+
!WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
512514
!$omp flush acq_rel
515+
!WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
513516
!$omp flush release
517+
!WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
514518
!$omp flush acquire
519+
!WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
515520
!ERROR: If memory-order-clause is RELEASE, ACQUIRE, or ACQ_REL, list items must not be specified on the FLUSH directive
516521
!$omp flush release (c)
522+
!WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
517523
!$omp flush seq_cst
524+
!WARNING: The syntax "FLUSH clause (object, ...)" has been deprecated, use "FLUSH(object, ...) clause" instead
518525
!ERROR: RELAXED clause is not allowed on the FLUSH directive
519526
!$omp flush relaxed
520527

flang/test/Semantics/OpenMP/deprecation.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -Werror
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp -Werror -fopenmp-version=52
22

33
! Check for deprecation of master directive and its combined/composite variants
44

0 commit comments

Comments
 (0)