[flang-commits] [flang] [Flang][OpenMP] Prevent unrequired implicit maps for private variables on composite directives (PR #217121)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Tue Sep 1 07:50:07 PDT 2026


================
@@ -3952,6 +3967,147 @@ static void collectSymbolsWithDynamicSubstring(
   symbolsWithDynamicSubstring = visitor.symbolsWithDynamicSubstring;
 }
 
+// Reverse search the composite/combined directive and return the first leaf
+// carrying a private clause, the OpenMP specification dictates that the first
+// leaf that can legally have a private clause becomes the owner.
+//
+// The function intentionally skips the node representing the root target
+// directive by setting the end (begin) point to the second leaf, the private
+// clauses on a standalone target region should apply through regular
+// privatization means. Otherwise, if we find no relevant leaf node (carrying a
+// private clause) we return the end of the iterator.
+static ConstructQueue::const_iterator
+findInnermostPrivateLeaf(ConstructQueue::const_iterator item,
----------------
skatrak wrote:

As it's currently implemented, this only considers explicitly compound constructs. Should it also handle nested constructs that could be combined because they have no other statements/directives in between? For example:
```f90
!$omp target
  !$omp teams distribute private(...)
  do ...
  !$omp end teams distribute
!$omp end target
```
This is something we already do when e.g. choosing which clauses need to be host-evaluated and when detecting SPMD kernels.

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


More information about the flang-commits mailing list