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

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Oct 20 17:00:13 PDT 2023


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

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.

>From b117cccfa805ee9dfe5e9d63b6ad5e32cfe9a083 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Fri, 20 Oct 2023 16:52:43 -0700
Subject: [PATCH] [flang] Silence a bogus warning

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.
---
 flang/lib/Semantics/resolve-names.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

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;



More information about the flang-commits mailing list