[flang-commits] [flang] 338f21a - [flang] Enforce specification function rules on callee, not call

peter klausler via flang-commits flang-commits at lists.llvm.org
Fri Sep 17 11:17:41 PDT 2021


Author: peter klausler
Date: 2021-09-17T10:59:54-07:00
New Revision: 338f21a4bd6b43d9a2eb00929d24cefeb0ccf581

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

LOG: [flang] Enforce specification function rules on callee, not call

A function can't be a specification function if it has a dummy procedure
argument, even if it's optional and unused.  So don't check the reference
for actual procedure arguments, but rather the characteristics of the
function.

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

Added: 
    

Modified: 
    flang/lib/Evaluate/check-expression.cpp
    flang/test/Semantics/expr-errors02.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 570aad663644..cb910caeecf0 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -460,9 +460,6 @@ class CheckSpecificationExprHelper
       : Base{*this}, scope_{s}, context_{context} {}
   using Base::operator();
 
-  Result operator()(const ProcedureDesignator &) const {
-    return "dummy procedure argument";
-  }
   Result operator()(const CoarrayRef &) const { return "coindexed reference"; }
 
   Result operator()(const semantics::Symbol &symbol) const {
@@ -541,6 +538,20 @@ class CheckSpecificationExprHelper
             "' not allowed for derived type components or type parameter"
             " values";
       }
+      if (auto procChars{
+              characteristics::Procedure::Characterize(x.proc(), context_)}) {
+        const auto iter{std::find_if(procChars->dummyArguments.begin(),
+            procChars->dummyArguments.end(),
+            [](const characteristics::DummyArgument &dummy) {
+              return std::holds_alternative<characteristics::DummyProcedure>(
+                  dummy.u);
+            })};
+        if (iter != procChars->dummyArguments.end()) {
+          return "reference to function '"s + ultimate.name().ToString() +
+              "' with dummy procedure argument '" + iter->name + '\'';
+        }
+      }
+      // References to internal functions are caught in expression semantics.
       // TODO: other checks for standard module procedures
     } else {
       const SpecificIntrinsic &intrin{DEREF(x.proc().GetSpecificIntrinsic())};

diff  --git a/flang/test/Semantics/expr-errors02.f90 b/flang/test/Semantics/expr-errors02.f90
index 8d72cb6c30d9..5349e65f0946 100644
--- a/flang/test/Semantics/expr-errors02.f90
+++ b/flang/test/Semantics/expr-errors02.f90
@@ -15,6 +15,7 @@ pure real function realfunc(x)
     pure integer function hasProcArg(p)
       import realfunc
       procedure(realfunc) :: p
+      optional :: p
     end function
   end interface
   integer :: coarray[*]
@@ -37,8 +38,8 @@ subroutine test(out, optional)
     integer, intent(in), optional :: optional
     !ERROR: Invalid specification expression: reference to OPTIONAL dummy argument 'optional'
     type(t(optional)) :: x5
-    !ERROR: Invalid specification expression: dummy procedure argument
-    type(t(hasProcArg(realfunc))) :: x6
+    !ERROR: Invalid specification expression: reference to function 'hasprocarg' with dummy procedure argument 'p'
+    type(t(hasProcArg())) :: x6
     !ERROR: Invalid specification expression: coindexed reference
     type(t(coarray[1])) :: x7
     type(t(kind(foo()))) :: x101 ! ok


        


More information about the flang-commits mailing list