[flang-commits] [flang] [Flang][Semantics] Allow declare target to be used on functions external to the declare targets scope (PR #122546)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Fri Jan 17 10:15:10 PST 2025


================
@@ -8298,6 +8345,44 @@ const parser::Name *DeclarationVisitor::FindComponent(
   return nullptr;
 }
 
+bool DeclarationVisitor::FindAndMarkDeclareTargetSymbol(
+    const parser::Name &name) {
+  if (!specPartState_.declareTargetNames.empty()) {
+    if (specPartState_.declareTargetNames.find(name.source) !=
+        specPartState_.declareTargetNames.end()) {
+      if (!currScope().IsTopLevel()) {
+        // Search preceding scopes until we find a matching symbol or run out
+        // of scopes to search, we skip the current scope as it's already been
+        // designated as implicit here.
+        Symbol *symbol = nullptr;
+        for (auto *scope = &currScope().parent();; scope = &scope->parent()) {
+          symbol = scope->FindSymbol(name.source);
+          if (symbol) {
+            if (symbol->test(Symbol::Flag::Subroutine) ||
+                symbol->test(Symbol::Flag::Function)) {
+              const auto pair{currScope().try_emplace(
+                  symbol->name(), Attrs{}, HostAssocDetails{*symbol})};
+              name.symbol = &*pair.first->second;
+              symbol->test(Symbol::Flag::Subroutine)
+                  ? name.symbol->set(Symbol::Flag::Subroutine)
+                  : name.symbol->set(Symbol::Flag::Function);
+              return true;
+            }
----------------
kparzysz wrote:

Yes, let's just add a break here, and I think it's good to go.

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


More information about the flang-commits mailing list