[flang-commits] [flang] [Flang][OpenMP] Fix crash when block.end() is missed (PR #147519)

Jack Styles via flang-commits flang-commits at lists.llvm.org
Tue Jul 8 06:58:18 PDT 2025


================
@@ -0,0 +1,75 @@
+! This reproducer hit an issue where when finding directive's, and end directive's would iterate over the block.end()
+! so Flang would crash. We should be able to parse this subroutine without flang crashing.
+! Reported in https://github.com/llvm/llvm-project/issues/147309 and https://github.com/llvm/llvm-project/pull/145917#issuecomment-3041570824
+
+!RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp -fopenmp-version=51 %s | FileCheck %s --check-prefix=CHECK-PARSE
+!RUN: %flang_fc1 -fdebug-unparse -fopenmp -fopenmp-version=51 %s | FileCheck %s --check-prefix=CHECK-UNPARSE
+
+subroutine loop_transformation_construct7
+implicit none
+real(kind=8), dimension(1:10, 2) :: a
+integer :: b,c
+
+!$omp target teams distribute parallel do collapse(2) private(b)
+do b = 1, 10
+  do c = 1, 10
+    a(b, 2) = a(c, 1)
+  end do
+end do
+end subroutine
----------------
Stylie777 wrote:

There is not anything missing from the function, it should be able to parse. A missing `end do` is also diagnosed before this stage yes.

Using `block.erase()` would advance the `nextIt` value to the next iterator. This could be `block.end()`. There is then potential for the while loop to never be equal to `block.end()`, and as such cause the compiler crash we saw. This test should cover it, as it should be possible to parse already.

https://github.com/llvm/llvm-project/pull/147519


More information about the flang-commits mailing list