[flang-commits] [flang] [flang][OpenMP] Implicit declarations of procedures in DECLARE_TARGET (PR #201935)
via flang-commits
flang-commits at lists.llvm.org
Fri Jun 5 22:29:35 PDT 2026
================
@@ -9756,6 +9742,28 @@ void ResolveNamesVisitor::HandleProcedureName(
Symbol::Flag flag, const parser::Name &name) {
CHECK(flag == Symbol::Flag::Function || flag == Symbol::Flag::Subroutine);
auto *symbol{FindSymbol(NonDerivedTypeScope(), name)};
+ // A symbol listed on OpenMP declare_target directive may be a variable
+ // or a procedure. If the directive is the first occurrence of the name,
+ // it will create an implicit declaration of an object (since the name
+ // is not used in a call at that location). If the name turns out to be
+ // that of a procedure, this is going to create a problem.
+ // If a symbol was created because of its appearance in a declare_target,
+ // a use in a call should override it with the procedure symbol.
+ Scope *ompDTScope{nullptr};
+ // A name implicitly declared by a DECLARE_TARGET may have been followed
+ // by an explcit declaration. Make sure the symbol is still implicit
+ // before doing anything.
+ if (WasDeclaredByOmpDeclareTarget(symbol) &&
----------------
MattPD wrote:
This recovery only runs on a call or function reference. If a declare-target name is never called in the scope (just listed, or passed as an actual argument), the symbol stays an implicit object and trips the declare-target variable rule. The removed `FindAndMarkDeclareTargetSymbol` (added by llvm/llvm-project#122546) resolved those non-call uses by searching the enclosing scopes. Is dropping that intentional?
Current trunk (before this PR) accepts this case: https://flang.godbolt.org/z/x7G7rEsnY
https://github.com/llvm/llvm-project/pull/201935
More information about the flang-commits
mailing list