[flang][OpenMP] Fix firstprivate with barrier
authorShraiysh Vaishay <Shraiysh.Vaishay@amd.com>
Mon, 20 Jun 2022 14:10:44 +0000 (19:40 +0530)
committerShraiysh Vaishay <Shraiysh.Vaishay@amd.com>
Tue, 21 Jun 2022 04:36:05 +0000 (10:06 +0530)
commitc858f4dbd5d06b227ff87bbe5ebd787d04148749
treeb8c8f864399373e538b827fd4cefa8692d43c268
parent34362f96d2c0bedc20e224f6d1ca4f0b9f66380c
[flang][OpenMP] Fix firstprivate with barrier

This patch fixes the unintentional data race in firstprivate
implementation. There is a Read-Write race when one thread tries
to copy the value inside the omp.parallel region while other
thread modifies it from inside the region (using pointers or
some other form of indirect access).

For detailed discussion please refer to [[ https://discourse.llvm.org/t/issues-with-the-current-implementation-of-privatization-in-openmp-with-fortran/62335 | discourse ]].

Reviewed By: kiranchandramohan, peixin, NimishMishra

Differential Revision: https://reviews.llvm.org/D125689
flang/lib/Lower/OpenMP.cpp
flang/test/Lower/OpenMP/omp-parallel-firstprivate-clause-scalar.f90
flang/test/Lower/OpenMP/omp-parallel-wsloop.f90