https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106662
Bug ID: 106662 Summary: [OpenMP] 'for simd firstprivate(j) lastprivate(j)' with 'parallel shared(j)' gives unexpected result Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: openmp, wrong-code Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org CC: jakub at gcc dot gnu.org, sandra at gcc dot gnu.org Target Milestone: --- [Lightly related to PR106504 - but that one uses 'parallel private' not shared.] The following program, converted to C++ from libgomp.fortran/pr27416-1.f90 and with 'simd' added to the workshare-loop construct, yields: * 22 with 'for' - i.e. the existing Fortran testcase, but C++-ified. and independent of 'num_threads(1)' * 22 with clang++-12 * 22 with icc 19 while * 16 is obtained with GCC (as if 0 and not 6 is firstprivatized) int main() { int j = 6; #pragma omp parallel num_threads (4) shared(j) { int i; #pragma omp for simd firstprivate (j) lastprivate (j) // private(i) for (i = 1; i <= 16; ++i) if (i == 16) j = j + i; } __builtin_printf("j = %i =?= %i\n", j, 6+16); if (j != 6+16) __builtin_abort(); return 0; } Likewise with a combined construct: ... #pragma omp parallel for simd num_threads (4) firstprivate (j) lastprivate (j) for (int i = 1; i <= 16; ++i) ... And likewise with the equivalent Fortran code.