[flang-commits] [flang] [flang][OpenMP] Fix wrong results for FORALL in a workshare construct (PR #211371)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Fri Jul 24 02:50:18 PDT 2026


================
@@ -485,7 +545,10 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
           delete singleBlock;
         } else {
           omp::SingleOperands singleOperands;
-          if (isLast)
+          // nowait and copyprivate are mutually exclusive on a single
+          // construct: the broadcast relies on the barrier at the end of the
+          // region.
+          if (isLast && copyprivateVars.empty())
----------------
tblah wrote:

[From Codex] When the final generated single gains a copyprivate value, this condition suppresses nowait even if the original workshare specified nowait. The resulting single introduces an implicit barrier at the transformed workshare end.

If the `single` `isLast`, I don't think we need the copyprivate broadcast to other threads - the generated single is the final work and no internal consumer remains.

https://github.com/llvm/llvm-project/pull/211371


More information about the flang-commits mailing list