[flang-commits] [flang] [flang][OpenMP] Don't privatize pre-determined symbols declare by nested `BLOCK`s (PR #152652)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Fri Aug 8 07:15:46 PDT 2025


================
@@ -553,8 +553,16 @@ void DataSharingProcessor::collectSymbols(
       return sym->test(semantics::Symbol::Flag::OmpImplicit);
     }
 
-    if (collectPreDetermined)
-      return sym->test(semantics::Symbol::Flag::OmpPreDetermined);
+    if (collectPreDetermined) {
+      // Collect pre-determined symbols only if they are defined by the current
+      // OpenMP evaluation. If `sym` is not defined by the current OpenMP
+      // evaluation then it is defined by a block nested within the OpenMP
+      // construct. This, in turn, means that the private allocation for the
+      // symbol will be emitted as part of the nested block and there is no need
+      // to prvatize it within the OpenMP construct.
+      return visitor.isSymbolDefineBy(sym, eval) &&
+             sym->test(semantics::Symbol::Flag::OmpPreDetermined);
----------------
luporl wrote:

If it doesn't break things, consider making this change for implicit symbols too, as they seem to have the same issue. Reproducer:

```fortran
subroutine sub
  implicit none
  integer :: i

  !$omp task
  do i=1,10
    block
      integer :: j
      j = 0
    end block
  end do
  !$omp end task
end subroutine
```

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


More information about the flang-commits mailing list