From 1465314cd3991a8515d2cef8c8c7a26bc599a540 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Tue, 25 Feb 2025 13:52:11 -0800 Subject: [PATCH] [flang] Silence spurious error When checking for conflicts between type-bound generic defined I/O procedures and non-type-bound defined I/O generic interfaces, don't worry about conflicts where the type-bound generic interface is inaccessible in the scope around the non-type-bound interface. Fixes https://github.com/llvm/llvm-project/issues/126797. --- flang/lib/Semantics/check-declarations.cpp | 7 ++--- flang/test/Semantics/io11.f90 | 31 ++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp index bf4dc16a15b4a..7b84e8f11cb50 100644 --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -3336,11 +3336,12 @@ void CheckHelper::CheckAlreadySeenDefinedIo(const DerivedTypeSpec &derivedType, return; } if (const Scope * dtScope{derivedType.scope()}) { - if (auto iter{dtScope->find(generic.name())}; iter != dtScope->end()) { + if (auto iter{dtScope->find(generic.name())}; iter != dtScope->end() && + IsAccessible(*iter->second, generic.owner())) { for (auto specRef : iter->second->get().specificProcs()) { const Symbol &specific{specRef->get().symbol()}; - if (specific == proc) { // unambiguous, accept - continue; + if (specific == proc) { + continue; // unambiguous, accept } if (const auto *specDT{GetDtvArgDerivedType(specific)}; specDT && evaluate::AreSameDerivedType(derivedType, *specDT)) { diff --git a/flang/test/Semantics/io11.f90 b/flang/test/Semantics/io11.f90 index 9b5ad1b8427d9..67f95b8cf64e3 100644 --- a/flang/test/Semantics/io11.f90 +++ b/flang/test/Semantics/io11.f90 @@ -689,3 +689,34 @@ module m26b procedure unformattedRead end interface end + +module m27a + type t + integer c + contains + procedure ur1 + generic, private :: read(unformatted) => ur1 + end type + contains + subroutine ur1(dtv,unit,iostat,iomsg) + class(t),intent(inout) :: dtv + integer,intent(in) :: unit + integer,intent(out) :: iostat + character(*),intent(inout) :: iomsg + read(unit,iotype,iostat=iostat,iomsg=iomsg) dtv%c + end +end +module m27b + use m27a + interface read(unformatted) + module procedure ur2 ! ok, t's generic is inaccessible + end interface + contains + subroutine ur2(dtv,unit,iostat,iomsg) + class(t),intent(inout) :: dtv + integer,intent(in) :: unit + integer,intent(out) :: iostat + character(*),intent(inout) :: iomsg + read(unit,iotype,iostat=iostat,iomsg=iomsg) dtv%c + end +end