[flang-commits] [PATCH] D93447: [Flang][openmp][openacc] Extend CheckNoBranching to handle branching provided by LabelEnforce.

sameeran joshi via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Dec 17 01:26:22 PST 2020


sameeranjoshi created this revision.
sameeranjoshi added reviewers: kiranchandramohan, clementval, tskeith, kiranktp.
Herald added subscribers: guansong, yaxunl.
sameeranjoshi requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.
Herald added a project: LLVM.

`CheckNoBranching` is currently handling only illegal branching out for constructs
with `Parser::Name` in them.
Extend the same for handling illegal branching out caused by `Parser::Label` based statements.
This patch could possibly solve one of the issues(typically branching out) mentioned in D92735 <https://reviews.llvm.org/D92735>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93447

Files:
  flang/lib/Semantics/check-directive-structure.h
  flang/lib/Semantics/check-omp-structure.cpp
  flang/test/Semantics/omp-parallell01.f90


Index: flang/test/Semantics/omp-parallell01.f90
===================================================================
--- flang/test/Semantics/omp-parallell01.f90
+++ flang/test/Semantics/omp-parallell01.f90
@@ -1,5 +1,4 @@
 ! RUN: %S/test_errors.sh %s %t %f18 -fopenmp
-! XFAIL: *
 
 ! OpenMP Version 4.5
 ! 2.5 parallel construct.
@@ -13,7 +12,7 @@
   do i = 1, 10
     do j = 1, 10
       print *, "Hello"
-      !ERROR: invalid branch to/from OpenMP structured block
+      !ERROR: Control flow escapes from PARALLEL
       goto 10
     end do
   end do
Index: flang/lib/Semantics/check-omp-structure.cpp
===================================================================
--- flang/lib/Semantics/check-omp-structure.cpp
+++ flang/lib/Semantics/check-omp-structure.cpp
@@ -125,14 +125,7 @@
   CheckMatching<parser::OmpBlockDirective>(beginDir, endDir);
 
   PushContextAndClauseSets(beginDir.source, beginDir.v);
-
-  switch (beginDir.v) {
-  case llvm::omp::OMPD_parallel:
-    CheckNoBranching(block, llvm::omp::OMPD_parallel, beginDir.source);
-    break;
-  default:
-    break;
-  }
+  CheckNoBranching(block, beginDir.v, beginDir.source);
 }
 
 void OmpStructureChecker::Leave(const parser::OpenMPBlockConstruct &) {
Index: flang/lib/Semantics/check-directive-structure.h
===================================================================
--- flang/lib/Semantics/check-directive-structure.h
+++ flang/lib/Semantics/check-directive-structure.h
@@ -15,7 +15,6 @@
 #include "flang/Common/enum-set.h"
 #include "flang/Semantics/semantics.h"
 #include "flang/Semantics/tools.h"
-
 #include <unordered_map>
 
 namespace Fortran::semantics {
@@ -43,6 +42,9 @@
 
   template <typename T> bool Pre(const parser::Statement<T> &statement) {
     currentStatementSourcePosition_ = statement.source;
+    if (statement.label.has_value()) {
+      labels_.insert(*statement.label);
+    }
     return true;
   }
 
@@ -54,6 +56,8 @@
   }
   void Post(const parser::StopStmt &) { EmitBranchOutError("STOP"); }
 
+  std::set<parser::Label> labels() { return labels_; }
+
 private:
   parser::MessageFormattedText GetEnclosingMsg() const {
     return {"Enclosing %s construct"_en_US, upperCaseDirName_};
@@ -103,6 +107,7 @@
   parser::CharBlock sourcePosition_;
   std::string upperCaseDirName_;
   D currentDirective_;
+  std::set<parser::Label> labels_;
 };
 
 // Generic structure checker for directives/clauses language such as OpenMP
@@ -226,6 +231,9 @@
       SayNotMatching(beginDir.source, endDir.source);
     }
   }
+  // Check illegal branching out of `Parser::Block` for `Parser::Name` based
+  // nodes (examples `Parser::ExitStmt`) along with `Parser::Label`
+  // based nodes (example `Parser::GotoStmt`).
   void CheckNoBranching(const parser::Block &block, D directive,
       const parser::CharBlock &directiveSource);
 
@@ -273,6 +281,11 @@
   NoBranchingEnforce<D> noBranchingEnforce{
       context_, directiveSource, directive, ContextDirectiveAsFortran()};
   parser::Walk(block, noBranchingEnforce);
+
+  LabelEnforce directiveLabelEnforce{context_, noBranchingEnforce.labels(),
+      directiveSource,
+      parser::ToUpperCaseLetters(getDirectiveName(directive).str()).c_str()};
+  parser::Walk(block, directiveLabelEnforce);
 }
 
 // Check that only clauses included in the given set are present after the given


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93447.312402.patch
Type: text/x-patch
Size: 3332 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20201217/1c90adea/attachment.bin>


More information about the flang-commits mailing list