https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109767
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #1) > Note, it is a Fortran only rule. > So, shared(j) on teams-loop-var.c is fully correct. Ups. True. > And, looking at Fortran, I already see it being private (by > fortran/openmp.cc (gfc_resolve_do_iterator)). > Thus, I don't see anything that needs to be done here. The problem is that for: !$omp teams !$omp loop the code GCC generates is: #pragma omp teams private(j) shared(i) #pragma omp distribute bind(teams) order(concurrent) private(i.2) lastprivate(i) #pragma omp parallel shared(j) lastprivate(i) #pragma omp for bind(teams) order(concurrent) private(i.1) #pragma omp simd lastprivate(i) bind(teams) order(concurrent) and there is a 'shared(j)' for parallel and no later 'private(j)' on either 'for' nor 'simd'. Thus, it is shared. - Which breaks the code. The problem is that PRIVATE happens early during parsing (→ search for gfc_resolve_do_iterator in openmp.cc) – but PARALLEL is only added in the middle end (→ gimplify_omp_loop).