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

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Mon Aug 11 06:20:13 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);
----------------
ergawy wrote:

The symbol and its defining construct are added only once to `symDefMap`. So, if we have a `block` and within that `block` a `DeclarationConstruct`, the symbol will be paired with the `DeclarationConstruct`. If the symbol is later referenced by the `eval` for which we are doing the privatization, `symDefMap` will not be updated again.

So the map track the first time we encounter a symbol and the context/construct where we did so.

Therefore, I thinkg, `isSymbolDefineByNestedDeclaration` is both more accurate and sufficient as a check.

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


More information about the flang-commits mailing list