https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128476
--- Comment #3 from Tobias Burnus <burnus at gcc dot gnu.org> ---
That seems to be due to the following code.
The problem seems to be that 'omp_current_do_collapse' does not handle
the case of having nested '!$omp loop'.
gcc/fortran/openmp.cc:
12844 /* Note a DO iterator variable. This is special in !$omp parallel
12845 construct, where they are predetermined private. */
12846
12847 void
12848 gfc_resolve_do_iterator (gfc_code *code, gfc_symbol *sym, bool
add_clause)
12849 {
12850 if (omp_current_ctx == NULL)
12851 return;
12852
12853 int i = omp_current_do_collapse;
12854 gfc_code *c = omp_current_do_code;
12855
12856 if (sym->attr.threadprivate)
12857 return;
12858
12859 /* !$omp do and !$omp parallel do iteration variable is predetermined
12860 private just in the !$omp do resp. !$omp parallel do construct,
12861 with no implications for the outer parallel constructs. */