[flang-commits] [flang] Adding warning for Master as it is deprecated in 5.2 (PR #98955)
via flang-commits
flang-commits at lists.llvm.org
Mon Jul 15 13:28:56 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Anchu Rajendran S (anchuraj)
<details>
<summary>Changes</summary>
Since `master` is deprecated from OpenMP spec 5.2, warning is added. Users are recommended to use `masked` directive instead.
---
Full diff: https://github.com/llvm/llvm-project/pull/98955.diff
7 Files Affected:
- (modified) flang/lib/Semantics/resolve-directives.cpp (+13-5)
- (modified) flang/test/Semantics/OpenMP/clause-validity01.f90 (+2)
- (modified) flang/test/Semantics/OpenMP/flush02.f90 (+1)
- (modified) flang/test/Semantics/OpenMP/nested-barrier.f90 (+2)
- (modified) flang/test/Semantics/OpenMP/nested-master.f90 (+12)
- (modified) flang/test/Semantics/OpenMP/nested-teams.f90 (+1)
- (modified) flang/test/Semantics/OpenMP/ordered-simd.f90 (+4)
``````````diff
diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index 16658d50c151c..bb0227e648b2e 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -734,6 +734,8 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
void AddOmpRequiresToScope(Scope &, WithOmpDeclarative::RequiresFlags,
std::optional<common::OmpAtomicDefaultMemOrderType>);
+ void IssueNonConformanceWarning(
+ llvm::omp::Directive D, parser::CharBlock source);
};
template <typename T>
@@ -1524,6 +1526,8 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPBlockConstruct &x) {
// TODO others
break;
}
+ if (beginDir.v == llvm::omp::Directive::OMPD_master)
+ IssueNonConformanceWarning(beginDir.v, beginDir.source);
ClearDataSharingAttributeObjects();
ClearPrivateDataSharingAttributeObjects();
ClearAllocateNames();
@@ -1634,11 +1638,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
break;
}
if (beginDir.v == llvm::omp::Directive::OMPD_target_loop)
- if (context_.ShouldWarn(common::UsageWarning::OpenMPUsage)) {
- context_.Say(beginDir.source,
- "Usage of directive %s is non-confirming to OpenMP standard"_warn_en_US,
- llvm::omp::getOpenMPDirectiveName(beginDir.v).str());
- }
+ IssueNonConformanceWarning(beginDir.v, beginDir.source);
ClearDataSharingAttributeObjects();
SetContextAssociatedLoopLevel(GetAssociatedLoopLevelFromClauses(clauseList));
@@ -2758,4 +2758,12 @@ void OmpAttributeVisitor::AddOmpRequiresToScope(Scope &scope,
} while (!scopeIter->IsGlobal());
}
+void OmpAttributeVisitor::IssueNonConformanceWarning(
+ llvm::omp::Directive D, parser::CharBlock source) {
+ if (context_.ShouldWarn(common::UsageWarning::OpenMPUsage)) {
+ context_.Say(source,
+ "Usage of directive %s is non-confirming to OpenMP standard"_warn_en_US,
+ llvm::omp::getOpenMPDirectiveName(D).str());
+ }
+}
} // namespace Fortran::semantics
diff --git a/flang/test/Semantics/OpenMP/clause-validity01.f90 b/flang/test/Semantics/OpenMP/clause-validity01.f90
index 22ac57065ffec..b683112685931 100644
--- a/flang/test/Semantics/OpenMP/clause-validity01.f90
+++ b/flang/test/Semantics/OpenMP/clause-validity01.f90
@@ -469,12 +469,14 @@
! 2.13.1 master
!$omp parallel
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$omp master
a=3.14
!$omp end master
!$omp end parallel
!$omp parallel
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: NUM_THREADS clause is not allowed on the MASTER directive
!$omp master num_threads(4)
a=3.14
diff --git a/flang/test/Semantics/OpenMP/flush02.f90 b/flang/test/Semantics/OpenMP/flush02.f90
index 18a0d0356bbd7..3e4d13212c477 100644
--- a/flang/test/Semantics/OpenMP/flush02.f90
+++ b/flang/test/Semantics/OpenMP/flush02.f90
@@ -80,6 +80,7 @@
!$omp parallel num_threads(4)
array = (/1, 2, 3, 4, 5, 6, 7, 8, 9, 10/)
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$omp master
!$omp flush (array)
!$omp end master
diff --git a/flang/test/Semantics/OpenMP/nested-barrier.f90 b/flang/test/Semantics/OpenMP/nested-barrier.f90
index cad31d7985607..788c06a86d8e9 100644
--- a/flang/test/Semantics/OpenMP/nested-barrier.f90
+++ b/flang/test/Semantics/OpenMP/nested-barrier.f90
@@ -75,6 +75,7 @@ program omp_nest_barrier
end do
!$omp end critical
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$omp master
do i = 1, 10
k = k + 1
@@ -107,6 +108,7 @@ program omp_nest_barrier
end do
!$omp end ordered
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$omp master
do i = 1, 10
!ERROR: `DISTRIBUTE` region has to be strictly nested inside `TEAMS` region.
diff --git a/flang/test/Semantics/OpenMP/nested-master.f90 b/flang/test/Semantics/OpenMP/nested-master.f90
index ef7d2cef6f88a..279eab0b9077a 100644
--- a/flang/test/Semantics/OpenMP/nested-master.f90
+++ b/flang/test/Semantics/OpenMP/nested-master.f90
@@ -9,6 +9,7 @@ program omp_nest_master
!$omp do
do i = 1, 10
k = k + 1
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$omp master
j = j -1
@@ -16,6 +17,7 @@ program omp_nest_master
end do
!$omp sections
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$omp master
do i = 1, 10
@@ -25,6 +27,7 @@ program omp_nest_master
!$omp end sections
!$omp single
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$omp master
do i = 1, 10
@@ -38,6 +41,7 @@ program omp_nest_master
!$omp task
do i = 1, 10
k = k + 1
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$omp master
j = j -1
@@ -48,6 +52,7 @@ program omp_nest_master
!$omp taskloop
do i = 1, 10
k = k + 1
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$omp master
j = j -1
@@ -58,6 +63,7 @@ program omp_nest_master
!$omp target parallel do simd
do i = 1, 10
k = k + 1
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!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 and the `ORDERED` construct with the `SIMD` clause.
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$omp master
@@ -69,6 +75,7 @@ program omp_nest_master
!$omp critical
do i = 1, 10
k = k + 1
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$omp master
j = j -1
!$omp end master
@@ -78,6 +85,7 @@ program omp_nest_master
!$omp ordered
do i = 1, 10
k = k + 1
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$omp master
j = j -1
!$omp end master
@@ -91,6 +99,7 @@ program omp_nest_master
!$omp distribute
do k =1, 10
print *, "hello"
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$omp master
j = j -1
!$omp end master
@@ -107,6 +116,7 @@ program omp_nest_master
!$omp distribute
do k =1, 10
print *, "hello"
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$omp master
j = j -1
!$omp end master
@@ -123,6 +133,7 @@ program omp_nest_master
!$omp distribute
do k =1, 10
print *, "hello"
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$omp master
j = j -1
@@ -140,6 +151,7 @@ program omp_nest_master
!$omp distribute
do k =1, 10
print *, "hello"
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$omp master
j = j -1
diff --git a/flang/test/Semantics/OpenMP/nested-teams.f90 b/flang/test/Semantics/OpenMP/nested-teams.f90
index 80c59e07fbaa6..9fef6d411ce41 100644
--- a/flang/test/Semantics/OpenMP/nested-teams.f90
+++ b/flang/test/Semantics/OpenMP/nested-teams.f90
@@ -42,6 +42,7 @@ program main
!$omp end teams
end do
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$omp master
!ERROR: TEAMS region can only be strictly nested within the implicit parallel region or TARGET region
!$omp teams
diff --git a/flang/test/Semantics/OpenMP/ordered-simd.f90 b/flang/test/Semantics/OpenMP/ordered-simd.f90
index c33ec745f2dda..b0fe9900a1f23 100644
--- a/flang/test/Semantics/OpenMP/ordered-simd.f90
+++ b/flang/test/Semantics/OpenMP/ordered-simd.f90
@@ -95,6 +95,7 @@ SUBROUTINE ORDERED_BAD(N)
!$OMP CRITICAL
C = C - A * B
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$OMP MASTER
DO I = 1,N
!ERROR: `ORDERED` region may not be closely nested inside of `CRITICAL`, `ORDERED`, explicit `TASK` or `TASKLOOP` region.
@@ -107,6 +108,7 @@ SUBROUTINE ORDERED_BAD(N)
!$OMP ORDERED
C = C - A * B
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!$OMP MASTER
DO I = 1,N
!ERROR: `ORDERED` region may not be closely nested inside of `CRITICAL`, `ORDERED`, explicit `TASK` or `TASKLOOP` region.
@@ -119,6 +121,7 @@ SUBROUTINE ORDERED_BAD(N)
!$OMP TASK
C = C - A * B
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$OMP MASTER
DO I = 1,N
@@ -133,6 +136,7 @@ SUBROUTINE ORDERED_BAD(N)
!$OMP TASKLOOP
DO J= 1,N
C = C - A * B
+ !WARNING: Usage of directive master is non-confirming to OpenMP standard
!ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
!$OMP MASTER
DO I = 1,N
``````````
</details>
https://github.com/llvm/llvm-project/pull/98955
More information about the flang-commits
mailing list