diff --git a/flang/lib/parser/parse-tree-visitor.h b/flang/lib/parser/parse-tree-visitor.h index 574cac27d5dd..f26838903447 100644 --- a/flang/lib/parser/parse-tree-visitor.h +++ b/flang/lib/parser/parse-tree-visitor.h @@ -85,6 +85,23 @@ template void Walk(std::list &x, M &mutator) { Walk(elem, mutator); } } +// When a list constitutes a Block, invoke the visitor or mutator. +template void Walk(const Block &x, V &visitor) { + if (visitor.Pre(x)) { + for (const auto &elem : x) { + Walk(elem, visitor); + } + visitor.Post(x); + } +} +template void Walk(Block &x, M &mutator) { + if (mutator.Pre(x)) { + for (auto &elem : x) { + Walk(elem, mutator); + } + } + mutator.Post(x); +} template void ForEachInTuple(const T &tuple, Func func) { if constexpr (I < std::tuple_size_v) { diff --git a/flang/lib/semantics/canonicalize-do.cc b/flang/lib/semantics/canonicalize-do.cc index 80cd6f044a4c..e0521f1e3a0d 100644 --- a/flang/lib/semantics/canonicalize-do.cc +++ b/flang/lib/semantics/canonicalize-do.cc @@ -14,6 +14,8 @@ #include "canonicalize-do.h" #include "../parser/parse-tree-visitor.h" +#include +#include namespace Fortran::parser { @@ -116,5 +118,4 @@ void CanonicalizeDo(Program &program) { CanonicalizationOfDoLoops canonicalizationOfDoLoops{labelInfos}; Walk(program, canonicalizationOfDoLoops); } - } // namespace Fortran::parser diff --git a/flang/test/semantics/canondo01.f90 b/flang/test/semantics/canondo01.f90 index d63ab5abdd7c..5cbb0ce29de6 100644 --- a/flang/test/semantics/canondo01.f90 +++ b/flang/test/semantics/canondo01.f90 @@ -12,6 +12,8 @@ ! See the License for the specific language governing permissions and ! limitations under the License. +! negative test -- invalid labels, out of range + ! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s ! CHECK: end do diff --git a/flang/test/semantics/canondo02.f90 b/flang/test/semantics/canondo02.f90 index 40992a03d61f..a54e4512b0e0 100644 --- a/flang/test/semantics/canondo02.f90 +++ b/flang/test/semantics/canondo02.f90 @@ -12,6 +12,8 @@ ! See the License for the specific language governing permissions and ! limitations under the License. +! negative test -- invalid labels, out of range + ! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s ! CHECK: end do diff --git a/flang/test/semantics/canondo03.f90 b/flang/test/semantics/canondo03.f90 index 4e822c700432..e6ec377aa290 100644 --- a/flang/test/semantics/canondo03.f90 +++ b/flang/test/semantics/canondo03.f90 @@ -12,6 +12,8 @@ ! See the License for the specific language governing permissions and ! limitations under the License. +! negative test -- invalid labels, out of range + ! RUN: ${F18} -funparse-with-symbols %s 2>&1 | ${FileCheck} %s ! CHECK: 10 continue ! CHECK: end do diff --git a/flang/test/semantics/canondo04.f90 b/flang/test/semantics/canondo04.f90 index e53a6ea58bd8..4260f202515f 100644 --- a/flang/test/semantics/canondo04.f90 +++ b/flang/test/semantics/canondo04.f90 @@ -23,14 +23,18 @@ program main print *, j1, j2, j3 do 2 j4=1,2 print *, j3, j4 -2 continue +2 end do else do 3 j3=3,4 print *, j1, j2, j3 do 3 j4=3,4 print *, j3, j4 -3 continue +3 end do end if print *, j1, j2 1 continue + do 4 j1=3,4 ! adjacent non-block DO loops +4 print *, j1 + do 5 j1=5,6 ! non-block DO loop at end of execution part +5 print *, j1 end