[flang-commits] [flang] [Flang] Avoid lowering temporary USE association symbols (PR #233665)
via flang-commits
flang-commits at lists.llvm.org
Mon Oct 19 21:10:17 PDT 2026
https://github.com/keepyixiao created https://github.com/llvm/llvm-project/pull/233665
Unused USE-associated names conflicting with a subprogram name create a temporary symbol for ambiguity diagnostics. Lowering could incorrectly instantiate that symbol and crash for deferred-length CHARACTER pointers.
Build UseErrorDetails directly without inserting a temporary UseDetails symbol into the scope.
Add a regression test for an unused same-name CHARACTER pointer.
Fixes https://github.com/llvm/llvm-project/issues/210320
>From 5a5efa711786b5f647dc3cb587f0f718769bf1d9 Mon Sep 17 00:00:00 2001
From: nudt_yixiao <1272950933 at qq.com>
Date: Tue, 20 Oct 2026 12:05:21 +0800
Subject: [PATCH] [Flang] Avoid lowering temporary USE association symbols
Unused USE-associated names conflicting with a subprogram name create a
temporary symbol for ambiguity diagnostics. Lowering could incorrectly
instantiate that symbol and crash for deferred-length CHARACTER pointers.
Build UseErrorDetails directly without inserting a temporary UseDetails symbol
into the scope.
Add a regression test for an unused same-name CHARACTER pointer.
---
flang/lib/Semantics/resolve-names.cpp | 5 ++-
flang/test/Semantics/resolve18.f90 | 47 +++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 06bc617ca7506..04fdf354de44e 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -4213,9 +4213,8 @@ bool ScopeHandler::ConvertToUseError(
location,
"'%s' is use-associated into a subprogram of the same name"_port_en_US,
used.name());
- SourceName created{context().GetTempName(currScope())};
- Symbol &tmpUse{MakeSymbol(created, Attrs(), UseDetails{location, used})};
- UseErrorDetails useError{tmpUse.get<UseDetails>()};
+ UseDetails useDetails{location, used};
+ UseErrorDetails useError{useDetails};
useError.add_occurrence(location, hostAssocDetails->symbol());
symbol.set_details(std::move(useError));
return true;
diff --git a/flang/test/Semantics/resolve18.f90 b/flang/test/Semantics/resolve18.f90
index b0827f88996c7..965b584ae9333 100644
--- a/flang/test/Semantics/resolve18.f90
+++ b/flang/test/Semantics/resolve18.f90
@@ -372,3 +372,50 @@ subroutine s_23_24
!ERROR: 'foo' is not a specific procedure
call ext(foo) ! definite error
end
+
+module m25
+
+ character(:), pointer :: TEST_COMPONENT_FOLLOWED_BY_REF
+ character(2), pointer :: c2
+
+ type t1
+ real :: x
+ end type
+
+ type t2
+ type(t1), pointer :: p
+ end type
+
+ type t3
+ character(:), allocatable :: a(:)
+ end type
+
+end module m25
+
+
+subroutine takes_real(x)
+ real, intent(in) :: x
+end subroutine takes_real
+
+
+subroutine test_char(x)
+ character(*), intent(in) :: x
+end subroutine test_char
+
+
+subroutine test_pointer_component_followed_by_component_ref(x)
+ use m25
+ type(t2) :: x
+
+ call takes_real(x%p%x)
+end subroutine test_pointer_component_followed_by_component_ref
+
+
+subroutine test_component_followed_by_ref(x)
+ !PORTABILITY: 'test_component_followed_by_ref' is use-associated into a subprogram of the same name [-Wuse-association-into-same-name-subprogram]
+ use m25
+ type(t3) :: x
+
+ call test_char(x%a(10))
+end subroutine test_component_followed_by_ref
+
More information about the flang-commits
mailing list