OSDN Git Service

[flang] Detect call to abstract interface
authorTim Keith <tkeith@nvidia.com>
Tue, 29 Dec 2020 00:36:32 +0000 (16:36 -0800)
committerTim Keith <tkeith@nvidia.com>
Tue, 29 Dec 2020 00:36:34 +0000 (16:36 -0800)
A subroutine call or function reference to an abstract interface is
not legal.

Differential Revision: https://reviews.llvm.org/D93872

flang/lib/Semantics/resolve-names.cpp
flang/test/Semantics/resolve20.f90

index 73c624a..2412758 100644 (file)
@@ -5879,7 +5879,10 @@ void ResolveNamesVisitor::HandleProcedureName(
       return; // reported error
     }
     CheckImplicitNoneExternal(name.source, *symbol);
-    if (IsProcedure(*symbol) || symbol->has<DerivedTypeDetails>() ||
+    if (symbol->has<SubprogramDetails>() &&
+        symbol->attrs().test(Attr::ABSTRACT)) {
+      Say(name, "Abstract interface '%s' may not be called"_err_en_US);
+    } else if (IsProcedure(*symbol) || symbol->has<DerivedTypeDetails>() ||
         symbol->has<ObjectEntityDetails>() ||
         symbol->has<AssocEntityDetails>()) {
       // Symbols with DerivedTypeDetails, ObjectEntityDetails and
index f9cfc7c..94bd4c1 100644 (file)
@@ -61,7 +61,18 @@ module m
     procedure(proc), deferred :: p1
   end type t1
 
+  abstract interface
+    function f()
+    end function
+  end interface
+
 contains
   subroutine bar
   end subroutine
+  subroutine test
+    !ERROR: Abstract interface 'foo' may not be called
+    call foo()
+    !ERROR: Abstract interface 'f' may not be called
+    x = f()
+  end subroutine
 end module