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

via flang-commits flang-commits at lists.llvm.org
Mon Jan 5 06:46:54 PST 2026


Author: Abid Qadeer
Date: 2026-01-05T14:46:49Z
New Revision: 316a9c52f022024978775c9af40ba829d0564888

URL: https://github.com/llvm/llvm-project/commit/316a9c52f022024978775c9af40ba829d0564888
DIFF: https://github.com/llvm/llvm-project/commit/316a9c52f022024978775c9af40ba829d0564888.diff

LOG: [flang] Ignore ambiguous use statement in use_stmt generation. (#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`.

Added: 
    flang/test/Lower/debug-use-stmt-ambiguous.f90

Modified: 
    flang/lib/Lower/Bridge.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index d4c066da44835..6c3631438a596 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