[flang-commits] [flang] [flang][OpenMP] Avoid marking named main programs as declare target (PR #190250)
Sairudra More via flang-commits
flang-commits at lists.llvm.org
Mon Apr 6 11:18:00 PDT 2026
Saieiei wrote:
Thanks for the review, @Jason-Van-Beusekom!
Two points of clarification:
**Does `sub_a` still get marked?**
Yes — but through a different path. The implicit-capture code at line 779–788 only ever marks the *owning procedure* returned by `eval.getOwningProcedure()`. For a bare `"new DEVICE rc=$?"omp declare target` inside an interface body hosted in a main program, PFT does not create a `FunctionLikeUnit` for the interface body; it walks up to the main program instead. So this path was never capable of marking `sub_a` — it was only ever going to mark `_QQmain` (which is the bug). `sub_a` gets correctly marked as a device routine when its separate *definition* file is compiled, because that file contains its own standalone `"new DEVICE rc=$?"omp declare target`. This is the standard OpenMP compilation model for separate interfaces/definitions.
**Does the fix break target offloading in named main programs?**
No. `"new DEVICE rc=$?"omp target` offload *regions* inside a named main program are completely unaffected — those are handled by a different lowering path. This fix only prevents `_QQmain` itself from being marked as an `omp.declare_target` device *routine*, which it can never legally be: the OpenMP 5.0 spec (section 7.8) limits the bare `declare target` directive to subroutines, functions, and interface bodies — not program units. Marking `_QQmain` as a device routine caused the cascade failure where every callee (Fortran I/O, module procedures, etc.) also gets pulled into device compilation.
https://github.com/llvm/llvm-project/pull/190250
More information about the flang-commits
mailing list