https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108741
Bug ID: 108741 Summary: [OpenMP] Wrong code for lastprivate with pointer iteration variable Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org CC: jakub at gcc dot gnu.org Target Milestone: --- The motivation is Fortran code, based on libgomp/testsuite/libgomp.fortran/non-rectangular-loop-3.f90 for PR107424 and with the patch applied from https://gcc.gnu.org/pipermail/gcc-patches/2023-January/610584.html However, the issue is preexisting and probably fails already since ever. It shows also up with a questionable C code, which tries to mimic the Fortran code. The problem is that '**a0' in the loop body points to invalid memory. //----- (questionable) C testcase ------ void foo(int **a1) { int j, a0; #pragma omp simd collapse(2) lastprivate(a0,a1,j) for (a0 = 1; a0 <= 10; a0++) for (j = 1; j <= 20; j++) **a1 = a0; /// Segfaults here as *a0 points to invalid memory if (**a1 != 10 || j != 21 || a0 != 11) __builtin_abort (); } int main() { int *a1, a2; a2 = 5; a1 = &a2; foo (&a1); return 0; } ! Fortran testcase implicit none integer, pointer :: a1 allocate(a1) call o(a1) contains subroutine o(a1) implicit none integer :: j integer, pointer :: a1 !$omp simd collapse(2) lastprivate(a1,j) do a1 = 1, 10 do j = 1, 20 end do end do if (a1 /= 11 .or. j /= 21) error stop end end