================
@@ -1433,16 +1433,38 @@ static void getDeclareTargetInfo(
} else {
List<Clause> clauses = makeClauses(construct.v.Clauses(), semaCtx);
if (clauses.empty()) {
+ // Case: implicit capture of the enclosing function/subroutine.
Fortran::lower::pft::FunctionLikeUnit *owningProc =
eval.getOwningProcedure();
- // Main programs are never device routines. Skip them so that a bare
- // '!$omp declare target' inside an interface body that lives in a named
- // main program does not incorrectly mark _QQmain as a device function.
- if (owningProc && !owningProc->isMainProgram()) {
- // Case: declare target, implicit capture of enclosing
- // function/subroutine.
+ bool owningProcNotMainProgram =
+ owningProc && !owningProc->isMainProgram();
+
+ const semantics::Symbol *owningSym =
+ owningProcNotMainProgram
+ ? &owningProc->getSubprogramSymbol()
+ : (owningProc ? owningProc->getMainProgramSymbol() : nullptr);
+
+ // A bare '!$omp declare target' may appear in the specification part of
+ // an interface body. In that case the PFT records the directive as an
+ // evaluation of the enclosing program unit rather than of the interface
+ // body's subprogram, so eval.getOwningProcedure() points at the main
+ // program. Detect this by comparing the program unit lexically
containing
+ // the directive with the procedure currently being lowered; when they
+ // differ, the directive belongs to the interface-body subprogram, which
+ // is the symbol we must capture.
+ const semantics::Scope &progUnitScope =
+ semantics::GetProgramUnitContaining(
+ semaCtx.FindScope(construct.v.source));
+ const semantics::Symbol *lexicalSym = progUnitScope.symbol();
+
+ if (lexicalSym && lexicalSym != owningSym) {
----------------
Saieiei wrote:
ould this regress procedures with alternate `ENTRY` points? `owningSym` follows
the active entry, while `lexicalSym` may remain the primary symbol, potentially
leaving secondary entries unmarked. Could we add a regression test?
https://github.com/llvm/llvm-project/pull/214184
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits