[flang-commits] [flang] [flang][OpenMP] Implicit declarations of procedures in DECLARE_TARGET (PR #201935)
via flang-commits
flang-commits at lists.llvm.org
Tue Jun 9 09:49:00 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) &&
+ symbol->flags().test(Symbol::Flag::Implicit)) {
+ // Implicit declaration of a symbol caused by being on a declare_target
+ // should only declare it as an object, not a procedure. This is because
+ // the 'x' in declare_target(x) looks like a use of a variable, not a
+ // procedure.
+ assert(!IsProcedure(*symbol) && "Should not be a procedure");
+ ompDTScope = const_cast<Scope *>(&symbol->owner());
+ ompDTScope->erase(symbol->name());
----------------
MattPD wrote:
Thanks, the pristine-implicit condition reads much cleaner, f06/f07/f08 covering the PARAMETER/SAVE/DIMENSION cases look good. Agreed on having to keep the Designator check: a value use of the name leaves no trace on the symbol (it stays a pristine implicit object), so the call site genuinely can't tell that an earlier `a = baz` happened without recording it the way you do here. Resolving.
https://github.com/llvm/llvm-project/pull/201935
More information about the flang-commits
mailing list