[flang-commits] [flang] [flang] Ignore ambiguous use statement in use_stmt generation. (PR #174387)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 5 03:23:49 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: Abid Qadeer (abidh)
<details>
<summary>Changes</summary>
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`.
---
Full diff: https://github.com/llvm/llvm-project/pull/174387.diff
2 Files Affected:
- (modified) flang/lib/Lower/Bridge.cpp (+3)
- (added) flang/test/Lower/debug-use-stmt-ambiguous.f90 (+30)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/174387
More information about the flang-commits
mailing list