The following example compiles incorrectly since at least clang 8.0.0:
#include <stdio.h> #include <omp.h> #define N 100 int main(void) { int i; int arr[N]; #pragma omp parallel // shared(i) shared(arr) #pragma omp for // private(i) for (i = 0; i < N; i++) { #pragma omp task // firstprivate(i) shared(arr) { printf("[thread %2d] i = %d\n", omp_get_thread_num(), i); arr[i] = i; } } for (i = 0; i < N; i++) { if (arr[i] != i) { fprintf(stderr, "FAIL: arr[%d] == %d\n", i, arr[i]); } } }
The iteration variable, i, should become private at the omp for construct and then become implicit firstprivate within the task region. What happens instead is that i is never privatized within the task construct. As the task construct is parsed, when a reference to i is determined, the implicit data-sharing attributes are computed incorrectly.