[flang-commits] [flang] [flang] Ignore ambiguous use statement in use_stmt generation. (PR #174387)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Mon Jan 5 03:23:19 PST 2026


https://github.com/abidh created https://github.com/llvm/llvm-project/pull/174387

The https://github.com/llvm/llvm-project/pull/168106 caused build failures in testcases which have ambiguous use statements. This PR fixes that by properly ignoring them in `emitUseStatementsFromFunit`.

>From 687a50e7ee6b3780c7c0ff92fed622925eb0b080 Mon Sep 17 00:00:00 2001
From: Abid Qadeer <haqadeer at amd.com>
Date: Mon, 5 Jan 2026 11:20:30 +0000
Subject: [PATCH] [flang] Ignore ambiguous use statement in use_stmt
 generation.

The https://github.com/llvm/llvm-project/pull/168106 caused build failures in testcases which have ambigious use statements. This PR fixes that by properly ignoring them in emitUseStatementsFromFunit.
---
 flang/lib/Lower/Bridge.cpp                    |  3 ++
 flang/test/Lower/debug-use-stmt-ambiguous.f90 | 30 +++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 flang/test/Lower/debug-use-stmt-ambiguous.f90

diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index a322e46ed0b9b..82c97ce91dc47 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -244,6 +244,9 @@ emitUseStatementsFromFunit(Fortran::lower::AbstractConverter &converter,
       if (ultimateSym.has<Fortran::semantics::DerivedTypeDetails>())
         return "";
 
+      if (ultimateSym.has<Fortran::semantics::UseErrorDetails>())
+        return "";
+
       if (const auto *generic =
               ultimateSym.detailsIf<Fortran::semantics::GenericDetails>()) {
         if (!generic->specific())
diff --git a/flang/test/Lower/debug-use-stmt-ambiguous.f90 b/flang/test/Lower/debug-use-stmt-ambiguous.f90
new file mode 100644
index 0000000000000..6e6ddb6c72657
--- /dev/null
+++ b/flang/test/Lower/debug-use-stmt-ambiguous.f90
@@ -0,0 +1,30 @@
+! RUN: %flang_fc1 -emit-hlfir -debug-info-kind=standalone %s -o -
+
+! The test checks that ambigious use statements don't cause a build failure
+! when generation of fir.use_stmt is enabled.
+module module_1st
+  integer :: mpi_integer = 1
+  integer :: mpi = 2, ssss = 3
+end module module_1st
+
+module module_2nd
+  integer :: dp, ssss
+end module module_2nd
+
+module module_3rd
+  use module_1st
+  use module_2nd
+  integer :: itmp
+end module module_3rd
+
+program test
+  use module_3rd, ONLY: ssss
+  use module_3rd, ONLY:
+  use module_1st
+  implicit none
+
+  ! Use non-ambiguous symbols
+  if (mpi_integer .ne. 1) print *, 'ng'
+  if (mpi .ne. 2) print *, 'ng'
+  print *, 'pass'
+end program test



More information about the flang-commits mailing list