[flang-commits] [clang] [flang] [llvm] [clang][flang][OpenMP] Fix context selector matching and scoring (PR #224431)

via flang-commits flang-commits at lists.llvm.org
Fri Oct 9 01:00:05 PDT 2026


================
@@ -7558,6 +7628,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:

An ignored compiler directive still prevents the following BLOCK from being associated with the selected TARGET. The scan skips intervening evaluations only when `isLoop` is true, so the BLOCK path returns null at the ignored directive.

You can reproduce this with `flang -fopenmp -fopenmp-version=52 -S -emit-llvm repro.f90 -o -`:

```fortran
subroutine selected()
  !$omp metadirective when(implementation={vendor(llvm)}: target)
  !dir$ ignored_comment
  block
    !$omp metadirective when(construct={target}: taskyield) otherwise(taskwait)
  end block
end subroutine
```

At 9c59c04, Flang warns that the directive was ignored, emits an empty TARGET, and places TASKWAIT outside it. Removing the ignored line or writing TARGET directly places TASKYIELD inside TARGET. The [merge base](https://github.com/llvm/llvm-project/commit/ae7f7ef515657eeb037e1cad045ade1a45cc7951) also loses this association, so this is a remaining case in the BLOCK fix rather than a new regression.

Could BLOCK association pass over this ignored directive without treating compiler directives with actual effects the same way?

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


More information about the flang-commits mailing list