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

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Mon Aug 11 04:26:58 PDT 2025


================
@@ -550,17 +558,20 @@ void DataSharingProcessor::collectSymbols(
         return false;
       }
 
-      return sym->test(semantics::Symbol::Flag::OmpImplicit);
-    }
-
-    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
+      // Collect implicit symbols only if they are not defined by a nested
+      // `DeclarationConstruct`. 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 privatize it within the OpenMP construct.
-      return visitor.isSymbolDefineBy(sym, eval) &&
+      return !visitor.isSymbolDefineByNestedDeclaration(sym) &&
+             sym->test(semantics::Symbol::Flag::OmpImplicit);
+    }
+
+    if (collectPreDetermined) {
+      // Similar to implicit symbols, collect pre-determined symbols only if
+      // they are not defined by a nested `DeclarationConstruct`
+      return !visitor.isSymbolDefineByNestedDeclaration(sym) &&
              sym->test(semantics::Symbol::Flag::OmpPreDetermined);
----------------
skatrak wrote:

Maybe it's because I'm not very familiar with this logic, but wouldn't the `visitor.isSymbolDefineBy(sym, eval)` check need to be preserved? E.g.: `visitor.isSymbolDefineBy(sym, eval) && !visitor.isSymbolDefineByNestedDeclaration(sym) && sym->test(semantics::Symbol::Flag::OmpPreDetermined)`.

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


More information about the flang-commits mailing list