This is an archive of the discontinued LLVM Phabricator instance.

[OPENMP] getDSA(): handle loop control variables
Needs ReviewPublic

Authored by Prince781 on Jul 17 2019, 3:16 PM.

Details

Reviewers
ABataev
rsmith
Summary

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.

Diff Detail

Event Timeline

Prince781 created this revision.Jul 17 2019, 3:16 PM
Prince781 updated this revision to Diff 210459.Jul 17 2019, 4:44 PM

Added a lit test.

Thanks for the report, but the fix is not quite correct.
I'll fix this myself. I just want to push it to 9.0 release branch ASAP.