[flang-commits] [flang] eb4d5b8 - [flang] Fix semantic analysis for "forall" targeted by "label"

via flang-commits flang-commits at lists.llvm.org
Fri Apr 8 09:28:54 PDT 2022


Author: PeixinQiao
Date: 2022-04-09T00:27:53+08:00
New Revision: eb4d5b852e1d922bce2f538bbafb688786ae2738

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

LOG: [flang] Fix semantic analysis for "forall" targeted by "label"

As Fortran 2018 3.18 states, the branch target statement can be
`forall-construct-stmt`, but cannot be `forall-stmt`. `forall-stmt` is
wrapped by `Statement` in `action-stmt` and `action-stmt` can be one
branch target statement. Fix the semantic analysis and add two
regression test cases in lowering.

Reviewed By: Jean Perier

Differential Revision: https://reviews.llvm.org/D123373

Added: 
    flang/test/Lower/forall/forall-construct-4.f90

Modified: 
    flang/lib/Semantics/resolve-labels.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-labels.cpp b/flang/lib/Semantics/resolve-labels.cpp
index 783ed91498f95..b099d24070cc7 100644
--- a/flang/lib/Semantics/resolve-labels.cpp
+++ b/flang/lib/Semantics/resolve-labels.cpp
@@ -122,7 +122,6 @@ constexpr Legality IsLegalBranchTarget(const parser::Statement<A> &) {
       std::is_same_v<A, parser::CriticalStmt> ||
       std::is_same_v<A, parser::EndCriticalStmt> ||
       std::is_same_v<A, parser::ForallConstructStmt> ||
-      std::is_same_v<A, parser::ForallStmt> ||
       std::is_same_v<A, parser::WhereConstructStmt> ||
       std::is_same_v<A, parser::EndFunctionStmt> ||
       std::is_same_v<A, parser::EndMpSubprogramStmt> ||
@@ -230,7 +229,7 @@ class ParseTreeAnalyzer {
         parser::BlockStmt, parser::ChangeTeamStmt, parser::CriticalStmt,
         parser::IfThenStmt, parser::NonLabelDoStmt, parser::SelectCaseStmt,
         parser::SelectRankStmt, parser::SelectTypeStmt,
-        parser::WhereConstructStmt>;
+        parser::ForallConstructStmt, parser::WhereConstructStmt>;
     using LabeledConstructEndStmts = std::tuple<parser::EndAssociateStmt,
         parser::EndBlockStmt, parser::EndChangeTeamStmt,
         parser::EndCriticalStmt, parser::EndDoStmt, parser::EndForallStmt,

diff  --git a/flang/test/Lower/forall/forall-construct-4.f90 b/flang/test/Lower/forall/forall-construct-4.f90
new file mode 100644
index 0000000000000..aed8d92962ade
--- /dev/null
+++ b/flang/test/Lower/forall/forall-construct-4.f90
@@ -0,0 +1,46 @@
+! Test forall lowering
+
+! RUN: bbc -emit-fir %s -o - | FileCheck %s
+
+!*** Test forall targeted by label
+subroutine test4_forall_construct()
+      integer :: a(2) = 1
+100   forall (i=1:2)
+        a(i) = a(i) + 1
+      end forall
+      if (a(1) > 3) goto 200
+      goto 100
+200   return
+end subroutine test4_forall_construct
+
+! CHECK-LABEL: func @_QPtest4_forall_construct
+! CHECK:   cf.br ^bb1
+! CHECK: ^bb1:  // 2 preds: ^bb0, ^bb2
+! CHECK:   %{{.*}} = fir.do_loop
+! CHECK:   cf.cond_br %{{.*}}, ^bb2, ^bb3
+! CHECK: ^bb2:  // pred: ^bb1
+! CHECK:   cf.br ^bb1
+! CHECK: ^bb3:  // pred: ^bb1
+! CHECK:   cf.br ^bb4
+! CHECK: ^bb4:  // pred: ^bb3
+! CHECK:   return
+
+subroutine test4_forall_construct2()
+      integer :: a(2) = 1
+100   forall (i=1:2) a(i) = a(i) + 1
+      if (a(1) > 3) goto 200
+      goto 100
+200   return
+end subroutine test4_forall_construct2
+
+! CHECK-LABEL: func @_QPtest4_forall_construct2
+! CHECK:   cf.br ^bb1
+! CHECK: ^bb1:  // 2 preds: ^bb0, ^bb2
+! CHECK:   %{{.*}} = fir.do_loop
+! CHECK:   cf.cond_br %{{.*}}, ^bb2, ^bb3
+! CHECK: ^bb2:  // pred: ^bb1
+! CHECK:   cf.br ^bb1
+! CHECK: ^bb3:  // pred: ^bb1
+! CHECK:   cf.br ^bb4
+! CHECK: ^bb4:  // pred: ^bb3
+! CHECK:   return


        


More information about the flang-commits mailing list