The following code (reduced code from a real-world project) gives an ICE but compiles with other vendors' compilers. It fails with GCC 10, 11 and trunk/12 with: 8 | if (kk == 7) exit | 1 internal compiler error: in gfc_trans_exit, at fortran/trans-stmt.cc:6147 0x69734b gfc_trans_exit(gfc_code*) ../../repos/gcc/gcc/fortran/trans-stmt.cc:6147 0xa17360 trans_code ../../repos/gcc/gcc/fortran/trans.cc:1947 0xa9e4b5 gfc_trans_if_1 ../../repos/gcc/gcc/fortran/trans-stmt.cc:1484 0xaa84cf gfc_trans_if(gfc_code*) ../../repos/gcc/gcc/fortran/trans-stmt.cc:1516 0xa17563 trans_code ../../repos/gcc/gcc/fortran/trans.cc:2004 0xa8ad58 gfc_trans_omp_code ../../repos/gcc/gcc/fortran/trans-openmp.cc:4399 0xa9a6aa gfc_trans_omp_do ../../repos/gcc/gcc/fortran/trans-openmp.cc:5381 !$omp target parallel do simd collapse(3) do ii = i1, i2 do jj = j1, j2 do kk = k1, k2 if (kk > 5) then k = 0 end if if (kk == 7) exit end do end do end do !$omp end target parallel do simd end
Actually, the EXIT does not make sense. There is: Fortran "final-loop-body must not contain any EXIT statement that would cause the termination of the5 innermost loop." → Accepts invalid for C/C++/Fortran I thought it did work in C/C++, but I messed up.
Why do you say accepts invalid for C/C++? void foo (int i1, int i2, int j1, int j2, int k1, int k2) { int k = 1; #pragma omp target parallel for simd collapse(3) firstprivate (k) for (int ii = i1; ii <= i2; ++ii) for (int jj = j1; jj <= j2; ++jj) for (int kk = k1; kk <= k2; ++kk) { if (kk > 5) k = 0; if (kk == 7) break; } } is certainly rejected: pr105242.c: In function ‘foo’: pr105242.c:13:13: error: break statement used with OpenMP for loop 13 | break; | ^~~~~ by both C and C++ (all the way back to GCC 6).
(In reply to Jakub Jelinek from comment #2) > Why do you say accepts invalid for C/C++? Because I messed up initially due to doing do much in parallel, found the issue, but forget to delete that line before hitting 'save'. I have patch – the problem is that the check does exist, but only takes care of a small subset of directives.
Submitted patch: https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593194.html
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>: https://gcc.gnu.org/g:469fad0161afeb9369010ad498198297993ca592 commit r12-8145-g469fad0161afeb9369010ad498198297993ca592 Author: Tobias Burnus <tobias@codesourcery.com> Date: Wed Apr 13 18:40:52 2022 +0200 OpenMP/Fortran: Fix EXIT in loop diagnostic [PR105242] gcc/fortran/ChangeLog: PR fortran/105242 * match.cc (match_exit_cycle): Handle missing OMP LOOP, DO and SIMD directives in the EXIT/CYCLE diagnostic. gcc/testsuite/ChangeLog: PR fortran/105242 * gfortran.dg/gomp/loop-exit.f90: New test.
FIXED on MAINLINE (= GCC 12)