[flang-commits] [flang] [flang] Make bug159554.f90 unsupported on Darwin (PR #171696)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Wed Jan 7 09:24:39 PST 2026


https://github.com/luporl updated https://github.com/llvm/llvm-project/pull/171696

>From 7c7c07f57ef00528b09cb4f647ee6eb0eccdb142 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Wed, 10 Dec 2025 17:44:03 -0300
Subject: [PATCH 1/3] [flang] Make lto-bc.f90 unsupported on Darwin

On Darwin, an additional unexpected warning is emitted:

```
/path/to/flang/test/Semantics/bug159554.f90:4:11: warning: 'c_funloc' should not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic [-Whomonymous-specific]
  interface c_funloc
            ^^^^^^^^
```
---
 flang/test/Semantics/bug159554.f90 | 1 +
 1 file changed, 1 insertion(+)

diff --git a/flang/test/Semantics/bug159554.f90 b/flang/test/Semantics/bug159554.f90
index f5a51ebc0b5cb..a9d89513b247f 100644
--- a/flang/test/Semantics/bug159554.f90
+++ b/flang/test/Semantics/bug159554.f90
@@ -1,3 +1,4 @@
+!UNSUPPORTED: system-darwin
 !RUN: %python %S/test_errors.py %s %flang_fc1
 use, intrinsic :: iso_c_binding
 interface c_funloc

>From 2f1ea051d0ce8a77c53313704e4f61fa1df340a9 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Wed, 7 Jan 2026 14:22:57 -0300
Subject: [PATCH 2/3] Revert "[flang] Make lto-bc.f90 unsupported on Darwin"

This reverts commit 7c7c07f57ef00528b09cb4f647ee6eb0eccdb142.
---
 flang/test/Semantics/bug159554.f90 | 1 -
 1 file changed, 1 deletion(-)

diff --git a/flang/test/Semantics/bug159554.f90 b/flang/test/Semantics/bug159554.f90
index a9d89513b247f..f5a51ebc0b5cb 100644
--- a/flang/test/Semantics/bug159554.f90
+++ b/flang/test/Semantics/bug159554.f90
@@ -1,4 +1,3 @@
-!UNSUPPORTED: system-darwin
 !RUN: %python %S/test_errors.py %s %flang_fc1
 use, intrinsic :: iso_c_binding
 interface c_funloc

>From 8bf5b04d3c8f3fb01c5177a976e3743dbbc30791 Mon Sep 17 00:00:00 2001
From: Leandro Lupori <leandro.lupori at linaro.org>
Date: Wed, 7 Jan 2026 13:53:02 -0300
Subject: [PATCH 3/3] [flang] Fix homonymous interface and procedure warning

When emitting an homonymous generic interface and procedure warning,
the source locations of the interface and the procedure were being
compared to find the one that occurred later in the source file.

The problem is that they could be in different source/module files,
which makes the comparison invalid.

Fix it by prioritizing the current source file over module files and
by comparing the source locations only when both the generic interface
and the procedure are not in module files.
---
 flang/lib/Semantics/resolve-names.cpp | 21 ++++++++++++++++++---
 flang/test/Semantics/bug159554.f90    |  1 +
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 345a0e4e8ecce..0d36f0ca38e5d 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -4535,9 +4535,24 @@ void InterfaceVisitor::CheckGenericProcedures(Symbol &generic) {
   ResolveSpecificsInGeneric(generic, true);
   auto &details{generic.get<GenericDetails>()};
   if (auto *proc{details.CheckSpecific()}) {
-    context().Warn(common::UsageWarning::HomonymousSpecific,
-        proc->name().begin() > generic.name().begin() ? proc->name()
-                                                      : generic.name(),
+    // Use the source location that is not in a module file for the warning,
+    // with the generic interface location being the default if both the
+    // interface and the procedure are in module files.
+    // If both the generic interface and procedure are not in module files,
+    // compare their locations and use the one that appears later in the
+    // source file.
+    SourceName at;
+    bool procInMod{context().IsInModuleFile(proc->name())};
+    bool genInMod{context().IsInModuleFile(generic.name())};
+    if ((!genInMod && procInMod) || (genInMod && procInMod)) {
+      at = generic.name();
+    } else if (!procInMod && genInMod) {
+      at = proc->name();
+    } else {
+      at = proc->name().begin() > generic.name().begin() ? proc->name()
+                                                         : generic.name();
+    }
+    context().Warn(common::UsageWarning::HomonymousSpecific, at,
         "'%s' should not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic"_warn_en_US,
         generic.name());
   }
diff --git a/flang/test/Semantics/bug159554.f90 b/flang/test/Semantics/bug159554.f90
index f5a51ebc0b5cb..3e935151df9f0 100644
--- a/flang/test/Semantics/bug159554.f90
+++ b/flang/test/Semantics/bug159554.f90
@@ -1,5 +1,6 @@
 !RUN: %python %S/test_errors.py %s %flang_fc1
 use, intrinsic :: iso_c_binding
+!WARNING: 'c_funloc' should not be the name of both a generic interface and a procedure unless it is a specific procedure of the generic [-Whomonymous-specific]
 interface c_funloc
 !ERROR: 'c_funloc' is already declared in this scoping unit
   function c_funloc()



More information about the flang-commits mailing list