[flang-commits] [flang] [flang] Silence a bogus warning (PR #69799)

via flang-commits flang-commits at lists.llvm.org
Fri Oct 20 17:01:21 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

A recent fix (https://github.com/llvm/llvm-project/pull/66232) to interpret a hitherto unknown name whose first appearance is as the target of a procedure pointer initializer as an external procedure has led to some inapproprite warning messages if the name is later defined as an external subroutine ("X was already declared as an external").

Ensure that the EXTERNAL attribute is correctly noted as being implicit, and that it's okay that neither the Subroutine nor Function flag has yet been set for the implicit external.

---
Full diff: https://github.com/llvm/llvm-project/pull/69799.diff


1 Files Affected:

- (modified) flang/lib/Semantics/resolve-names.cpp (+7-1) 


``````````diff
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 90c14806afbf82d..5557ca5d8ba8541 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -4191,18 +4191,23 @@ bool SubprogramVisitor::HandlePreviousCalls(
     // ENTRY's name.  We have to replace that symbol in situ to avoid the
     // obligation to rewrite symbol pointers in the parse tree.
     if (!symbol.test(subpFlag)) {
+      auto other{subpFlag == Symbol::Flag::Subroutine
+              ? Symbol::Flag::Function
+              : Symbol::Flag::Subroutine};
       // External statements issue an explicit EXTERNAL attribute.
       if (symbol.attrs().test(Attr::EXTERNAL) &&
           !symbol.implicitAttrs().test(Attr::EXTERNAL)) {
         // Warn if external statement previously declared.
         Say(name,
             "EXTERNAL attribute was already specified on '%s'"_warn_en_US);
-      } else {
+      } else if (symbol.test(other)) {
         Say2(name,
             subpFlag == Symbol::Flag::Function
                 ? "'%s' was previously called as a subroutine"_err_en_US
                 : "'%s' was previously called as a function"_err_en_US,
             symbol, "Previous call of '%s'"_en_US);
+      } else {
+        symbol.set(subpFlag);
       }
     }
     EntityDetails entity;
@@ -8163,6 +8168,7 @@ bool ResolveNamesVisitor::Pre(const parser::PointerAssignmentStmt &x) {
       // Unknown target of procedure pointer must be an external procedure
       Symbol &symbol{MakeSymbol(
           context().globalScope(), name->source, Attrs{Attr::EXTERNAL})};
+      symbol.implicitAttrs().set(Attr::EXTERNAL);
       Resolve(*name, symbol);
       ConvertToProcEntity(symbol);
       return false;

``````````

</details>


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


More information about the flang-commits mailing list