From 5be7f8a666daee086042da0650b595a0938e3da2 Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Fri, 17 Feb 2023 17:12:14 -0800 Subject: [PATCH] [flang] Catch attempt to misuse an abstract procedure in a generic interface A procedure defined in an ABSTRACT INTERFACE may not appear as a specific procedure in a generic interface. Differential Revision: https://reviews.llvm.org/D145102 --- flang/lib/Semantics/check-declarations.cpp | 8 ++++++++ flang/test/Semantics/generic02.f90 | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp index 8321bbc..8c38d0f 100644 --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -1374,6 +1374,14 @@ void CheckHelper::CheckSpecificsAreDistinguishable( GenericKind kind{details.kind()}; DistinguishabilityHelper helper{context_}; for (const Symbol &specific : details.specificProcs()) { + if (specific.attrs().test(Attr::ABSTRACT)) { + if (auto *msg{messages_.Say(generic.name(), + "Generic interface '%s' must not use abstract interface '%s' as a specific procedure"_err_en_US, + generic.name(), specific.name())}) { + msg->Attach( + specific.name(), "Definition of '%s'"_en_US, specific.name()); + } + } if (const Procedure *procedure{Characterize(specific)}) { if (procedure->HasExplicitInterface()) { helper.Add(generic, kind, specific, *procedure); diff --git a/flang/test/Semantics/generic02.f90 b/flang/test/Semantics/generic02.f90 index e4f7fe6..551b897 100644 --- a/flang/test/Semantics/generic02.f90 +++ b/flang/test/Semantics/generic02.f90 @@ -1,10 +1,16 @@ ! RUN: %python %S/test_errors.py %s %flang_fc1 program test + !ERROR: Generic interface 'generic' must not use abstract interface 'abstract' as a specific procedure interface generic subroutine explicit(n) integer, intent(in) :: n end subroutine procedure implicit + procedure abstract + end interface + abstract interface + subroutine abstract + end subroutine end interface !ERROR: Specific procedure 'implicit' of generic interface 'generic' must have an explicit interface external implicit -- 2.7.4