================
@@ -7633,6 +7675,18 @@ static void genMetadirective(lower::AbstractConverter 
&converter,
     }
   }
 
+  if (!hasLoopAssociatedCandidate &&
+      llvm::any_of(reachableVariantSpecs, [](const auto *spec) {
+        return spec && hasDirectiveAssociation(spec->DirId(),
+                                               llvm::omp::Association::Block);
+      }))
+    associatedBlockEval = spliceAssociatedEval<parser::BlockConstruct>(
----------------
MattPD wrote:

A BLOCK associated with a metadirective is not part of the metadirective's 
parse tree. `visitAllSymbols(eval, ...)` in TARGET implicit-map collection and 
`collectSymbolsWithDynamicSubstring` still walk only that parse tree, so they 
miss variables referenced in the BLOCK.

You can reproduce this by saving the following to `repro.f90` and running 
`flang -fc1 -fopenmp -fopenmp-version=52 -emit-hlfir -module-dir /tmp repro.f90 
-o -`:

```fortran
subroutine s(x)
  integer :: x
  !$omp metadirective when(implementation={vendor(llvm)}: target)
  block
    x = x + 1
  end block
end subroutine
```

At 1850727, FIR verification fails with `'fir.load' op using value defined 
outside the region`. A directly written TARGET and a `begin metadirective` 
selecting TARGET both capture `x` and compile. At 9d79b83, Flang compiles the 
input but leaves the BLOCK outside an empty TARGET. The selection here is 
static, so the failure differs from the [runtime-selection 
failure](https://github.com/llvm/llvm-project/pull/224431#issuecomment-5840331662)
 reported earlier.

Could both symbol walks include the spliced BLOCK evaluation before the 
selected TARGET is lowered?

https://github.com/llvm/llvm-project/pull/224431
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to