[flang-commits] [flang] a51d263 - Adding warning for Master as it is deprecated in 5.2 (#98955)

via flang-commits flang-commits at lists.llvm.org
Tue Jul 23 09:19:57 PDT 2024


Author: Anchu Rajendran S
Date: 2024-07-23T09:19:54-07:00
New Revision: a51d2632827bffa0fe8f21a1c8807985413155a3

URL: https://github.com/llvm/llvm-project/commit/a51d2632827bffa0fe8f21a1c8807985413155a3
DIFF: https://github.com/llvm/llvm-project/commit/a51d2632827bffa0fe8f21a1c8807985413155a3.diff

LOG: Adding warning for Master as it is deprecated in 5.2 (#98955)

Since `master` is deprecated from OpenMP spec 5.2, warning is added.
Using `masked` is the recommended alternative as per spec

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-directives.cpp
    flang/test/Semantics/OpenMP/clause-validity01.f90
    flang/test/Semantics/OpenMP/flush02.f90
    flang/test/Semantics/OpenMP/nested-barrier.f90
    flang/test/Semantics/OpenMP/nested-master.f90
    flang/test/Semantics/OpenMP/nested-teams.f90
    flang/test/Semantics/OpenMP/ordered-simd.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index ddb928409ee74..e9811151972fe 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));
 
@@ -2800,4 +2800,21 @@ void OmpAttributeVisitor::AddOmpRequiresToScope(Scope &scope,
   } while (!scopeIter->IsGlobal());
 }
 
+void OmpAttributeVisitor::IssueNonConformanceWarning(
+    llvm::omp::Directive D, parser::CharBlock source) {
+  std::string warnStr = "";
+  std::string dirName = llvm::omp::getOpenMPDirectiveName(D).str();
+  switch (D) {
+  case llvm::omp::OMPD_master:
+    warnStr = "OpenMP directive '" + dirName +
+        "' has been deprecated, please use 'masked' instead.";
+    break;
+  case llvm::omp::OMPD_target_loop:
+  default:
+    warnStr = "OpenMP directive '" + dirName + "' has been deprecated.";
+  }
+  if (context_.ShouldWarn(common::UsageWarning::OpenMPUsage)) {
+    context_.Say(source, "%s"_warn_en_US, warnStr);
+  }
+}
 } // namespace Fortran::semantics

diff  --git a/flang/test/Semantics/OpenMP/clause-validity01.f90 b/flang/test/Semantics/OpenMP/clause-validity01.f90
index 745895248ddf4..020d63f735596 100644
--- a/flang/test/Semantics/OpenMP/clause-validity01.f90
+++ b/flang/test/Semantics/OpenMP/clause-validity01.f90
@@ -470,12 +470,14 @@
 ! 2.13.1 master
 
   !$omp parallel
+  !WARNING: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
   !$omp master
   a=3.14
   !$omp end master
   !$omp end parallel
 
   !$omp parallel
+  !WARNING: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
   !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..d12c76bad0334 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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !$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..aae283229e330 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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
   !$omp master
   do i = 1, 10
     k = k + 1
@@ -107,6 +108,7 @@ program omp_nest_barrier
   end do
   !$omp end ordered
 
+  !WARNING: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
   !$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..069de67cafae2 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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
   !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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
   !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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !$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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !$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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
       !$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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
       !$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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
       !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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
       !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..f3b96b0ab4390 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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
   !$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..ed52b75949100 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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !$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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !$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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !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: OpenMP directive 'master' has been deprecated, please use 'masked' instead.
     !ERROR: `MASTER` region may not be closely nested inside of `WORKSHARING`, `LOOP`, `TASK`, `TASKLOOP`, or `ATOMIC` region.
     !$OMP MASTER
     DO I = 1,N


        


More information about the flang-commits mailing list