[flang] Catch error: COMMON block and implicit interface external subprogram with...
authorPeter Klausler <pklausler@nvidia.com>
Mon, 26 Jun 2023 17:00:10 +0000 (10:00 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Tue, 27 Jun 2023 20:18:30 +0000 (13:18 -0700)
Declaration checking catches the error of a COMMON block and a subprogram
definition having the same name, but misses the case of a COMMON block
and an a reference to an external subprogram with an implicit interface.
Fix.  Fixes bug https://github.com/llvm/llvm-project/issues/63247.

Differential Revision: https://reviews.llvm.org/D153786

flang/lib/Semantics/check-declarations.cpp
flang/test/Semantics/declarations04.f90

index baf7af2..24ee1b2 100644 (file)
@@ -2552,7 +2552,8 @@ static std::optional<std::string> DefinesGlobalName(const Symbol &symbol) {
   } else {
     const std::string *bindC{symbol.GetBindName()};
     if (symbol.has<CommonBlockDetails>() ||
-        IsExternalProcedureDefinition(symbol)) {
+        IsExternalProcedureDefinition(symbol) ||
+        (symbol.owner().IsGlobal() && IsExternal(symbol))) {
       return bindC ? *bindC : symbol.name().ToString();
     } else if (bindC &&
         (symbol.has<ObjectEntityDetails>() || IsModuleProcedure(symbol))) {
index f061cb9..6b33578 100644 (file)
@@ -23,3 +23,9 @@ block data ext3
   !PORTABILITY: Global name 'ext4' conflicts with a module
   common /ext4/ x
 end
+
+subroutine s
+  !ERROR: Two entities have the same global name 'foo'
+  common /foo/n
+  call foo
+end