[flang-commits] [flang] [flang] Fix crash when GoTo exits acc.loop region (PR #187613)
via flang-commits
flang-commits at lists.llvm.org
Fri Mar 20 06:26:13 PDT 2026
================
@@ -0,0 +1,33 @@
+! Test that GoTo exiting an acc.loop seq region generates acc.yield
+! instead of an illegal cross-region cf.br that would crash the compiler.
+! RUN: bbc -fopenacc -emit-hlfir %s -o - | FileCheck %s
+
+! CHECK-LABEL: func.func @_QPfoo
+subroutine foo(N, A, B)
+ implicit real*8 (a-h, o-z)
+ !$acc routine gang
+ dimension A(*), B(*)
+ !$acc loop gang vector
+ do 100 i = 1, N
+ !$acc loop seq
+ do 10 j = 1, 1000
+ if (A(i) .gt. B(i)) goto 20
+10 continue
+20 B(i) = A(i)
----------------
jeanPerier wrote:
What is there is another statement between the end of the loop (`10 continue`) and the statement target ("20 B(i) = A(i)")?
It seems that with your change the compiler is treating the goto as an EXIT and would fall through to that statement. I think you need to propagate the jump at the end of the acc.loop via some acc.loop result.
This may also be made more complex by assigned gotos where the branch may jump to a list of several targets.
And this should also works with the case where there are several gotos inside the loop branching to different targets.
https://github.com/llvm/llvm-project/pull/187613
More information about the flang-commits
mailing list