https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67986
Bug ID: 67986 Summary: OpenMP collapse - invalid code generated. Product: gcc Version: 4.9.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgomp Assignee: unassigned at gcc dot gnu.org Reporter: lbukata at gmail dot com CC: jakub at gcc dot gnu.org Target Milestone: --- Created attachment 36525 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36525&action=edit Simple demonstration of the bug. Invalid code for the following code: #pragma omp parallel for collapse(2) for (int32_t i = 0; i < N-1; ++i) { for (int32_t j = i+1; j < N; ++j) { #pragma omp critical cout<<"(i,j): ("<<i<<","<<j<<")"<<endl; } } Sequential code generates valid pairs of indices, however, the parallel code neglects the dependency of inner loop range on outer loop variable. The full source is attached. Tested on both GCC 4.8.5 and GCC 4.9.3 with the same result. The distro is Gentoo Linux 2015.