[flang-commits] [flang] f782d5e - [flang] Detect call to abstract interface

Tim Keith via flang-commits flang-commits at lists.llvm.org
Mon Dec 28 16:41:58 PST 2020


Author: Tim Keith
Date: 2020-12-28T16:36:34-08:00
New Revision: f782d5ea86f6fc82b51a0de688bf292f39cc4814

URL: https://github.com/llvm/llvm-project/commit/f782d5ea86f6fc82b51a0de688bf292f39cc4814
DIFF: https://github.com/llvm/llvm-project/commit/f782d5ea86f6fc82b51a0de688bf292f39cc4814.diff

LOG: [flang] Detect call to abstract interface

A subroutine call or function reference to an abstract interface is
not legal.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 73c624aefa22..2412758f340b 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -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

diff  --git a/flang/test/Semantics/resolve20.f90 b/flang/test/Semantics/resolve20.f90
index f9cfc7cb1006..94bd4c18a6a0 100644
--- a/flang/test/Semantics/resolve20.f90
+++ b/flang/test/Semantics/resolve20.f90
@@ -61,7 +61,18 @@ subroutine forward
     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


        


More information about the flang-commits mailing list