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

flang/test/Semantics/OpenMP/flush02.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878

7979
!$omp parallel num_threads(4)
8080
array = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/)
81-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
8281
!$omp master
8382
!$omp flush (array)
8483
!$omp end master

flang/test/Semantics/OpenMP/nested-barrier.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ program omp_nest_barrier
7575
end do
7676
!$omp end critical
7777

78-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
7978
!$omp master
8079
do i = 1, 10
8180
k = k + 1
@@ -108,7 +107,6 @@ program omp_nest_barrier
108107
end do
109108
!$omp end ordered
110109

111-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
112110
!$omp master
113111
do i = 1, 10
114112
!ERROR: `DISTRIBUTE` region has to be strictly nested inside `TEAMS` region.

flang/test/Semantics/OpenMP/nested-master.f90

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ program omp_nest_master
99
!$omp do
1010
do i = 1, 10
1111
k = k + 1
12-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
1312
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
1413
!$omp master
1514
j = j -1
1615
!$omp end master
1716
end do
1817

1918
!$omp sections
20-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
2119
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
2220
!$omp master
2321
do i = 1, 10
@@ -27,7 +25,6 @@ program omp_nest_master
2725
!$omp end sections
2826

2927
!$omp single
30-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
3128
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
3229
!$omp master
3330
do i = 1, 10
@@ -41,7 +38,6 @@ program omp_nest_master
4138
!$omp task
4239
do i = 1, 10
4340
k = k + 1
44-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
4541
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
4642
!$omp master
4743
j = j -1
@@ -52,7 +48,6 @@ program omp_nest_master
5248
!$omp taskloop
5349
do i = 1, 10
5450
k = k + 1
55-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
5651
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
5752
!$omp master
5853
j = j -1
@@ -63,7 +58,6 @@ program omp_nest_master
6358
!$omp target parallel do simd
6459
do i = 1, 10
6560
k = k + 1
66-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
6761
!ERROR: The only OpenMP constructs that can be encountered during execution of a 'SIMD' region are the `ATOMIC` construct, the `LOOP` construct, the `SIMD` construct, the `SCAN` construct and the `ORDERED` construct with the `SIMD` clause.
6862
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
6963
!$omp master
@@ -75,7 +69,6 @@ program omp_nest_master
7569
!$omp critical
7670
do i = 1, 10
7771
k = k + 1
78-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
7972
!$omp master
8073
j = j -1
8174
!$omp end master
@@ -85,7 +78,6 @@ program omp_nest_master
8578
!$omp ordered
8679
do i = 1, 10
8780
k = k + 1
88-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
8981
!$omp master
9082
j = j -1
9183
!$omp end master
@@ -99,7 +91,6 @@ program omp_nest_master
9991
!$omp distribute
10092
do k =1, 10
10193
print *, "hello"
102-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
10394
!$omp master
10495
j = j -1
10596
!$omp end master
@@ -116,7 +107,6 @@ program omp_nest_master
116107
!$omp distribute
117108
do k =1, 10
118109
print *, "hello"
119-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
120110
!$omp master
121111
j = j -1
122112
!$omp end master
@@ -133,7 +123,6 @@ program omp_nest_master
133123
!$omp distribute
134124
do k =1, 10
135125
print *, "hello"
136-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
137126
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
138127
!$omp master
139128
j = j -1
@@ -151,7 +140,6 @@ program omp_nest_master
151140
!$omp distribute
152141
do k =1, 10
153142
print *, "hello"
154-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
155143
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
156144
!$omp master
157145
j = j -1

flang/test/Semantics/OpenMP/nested-teams.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ program main
4242
!$omp end teams
4343
end do
4444

45-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
4645
!$omp master
4746
!ERROR: TEAMS region can only be strictly nested within the implicit parallel region or TARGET region
4847
!$omp teams

flang/test/Semantics/OpenMP/ordered-simd.f90

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ SUBROUTINE ORDERED_BAD(N)
9595

9696
!$OMP CRITICAL
9797
C = C - A * B
98-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
9998
!$OMP MASTER
10099
DO I = 1,N
101100
!ERROR: `ORDERED` region may not be closely nested inside of `CRITICAL`, `ORDERED`, explicit `TASK` or `TASKLOOP` region.
@@ -108,7 +107,6 @@ SUBROUTINE ORDERED_BAD(N)
108107

109108
!$OMP ORDERED
110109
C = C - A * B
111-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
112110
!$OMP MASTER
113111
DO I = 1,N
114112
!ERROR: `ORDERED` region may not be closely nested inside of `CRITICAL`, `ORDERED`, explicit `TASK` or `TASKLOOP` region.
@@ -121,7 +119,6 @@ SUBROUTINE ORDERED_BAD(N)
121119

122120
!$OMP TASK
123121
C = C - A * B
124-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
125122
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
126123
!$OMP MASTER
127124
DO I = 1,N
@@ -136,7 +133,6 @@ SUBROUTINE ORDERED_BAD(N)
136133
!$OMP TASKLOOP
137134
DO J= 1,N
138135
C = C - A * B
139-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
140136
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
141137
!$OMP MASTER
142138
DO I = 1,N

flang/test/Semantics/OpenMP/parallel-master-goto.f90

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
!ERROR: invalid branch leaving an OpenMP structured block
88
goto 10
99
end do
10-
!WARNING: OpenMP directive MASTER has been deprecated, please use MASKED instead.
1110
!$omp master
1211
10 print *, i
1312
!$omp end master

0 commit comments

Comments
 (0)