[flang-commits] [PATCH] D145102: [flang] Catch attempt to misuse an abstract procedure in a generic interface

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Mar 1 11:53:34 PST 2023


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

A procedure defined in an ABSTRACT INTERFACE may not appear as
a specific procedure in a generic interface.


https://reviews.llvm.org/D145102

Files:
  flang/lib/Semantics/check-declarations.cpp
  flang/test/Semantics/generic02.f90


Index: flang/test/Semantics/generic02.f90
===================================================================
--- flang/test/Semantics/generic02.f90
+++ 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
Index: flang/lib/Semantics/check-declarations.cpp
===================================================================
--- flang/lib/Semantics/check-declarations.cpp
+++ flang/lib/Semantics/check-declarations.cpp
@@ -1365,6 +1365,14 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145102.501615.patch
Type: text/x-patch
Size: 1673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230301/a1f8d378/attachment-0001.bin>


More information about the flang-commits mailing list