[flang-commits] [flang] [Flang][Semantics] Allow declare target to be used on functions external to the declare targets scope (PR #122546)
via flang-commits
flang-commits at lists.llvm.org
Fri Jan 17 10:09:25 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;
+ }
----------------
agozillon wrote:
Yes, I wasn't too sure what the ideal solution would be in those cases personally, was one of the pieces I was looking for some input on! I can try to adjust it to just break the loop if we find something that's not a function/subroutine and let the original behavior continue in those cases, we can then adjust the behavior further if we find a need for it. Do you think that would be a reasonable approach in these cases for the time being?
https://github.com/llvm/llvm-project/pull/122546
More information about the flang-commits
mailing list