[flang-commits] [flang] [Flang] Add partial support for lowering procedure pointer assignment. (PR #70461)

via flang-commits flang-commits at lists.llvm.org
Fri Oct 27 09:00:38 PDT 2023


================
@@ -560,6 +578,35 @@ struct TypeBuilderImpl {
     derivedTypeInConstruction.pop_back();
   }
 
+  mlir::Type genProcType(const Fortran::semantics::Symbol *proc,
+                         mlir::Location loc) {
+    if (auto procDetails{proc->detailsIf<SubprogramDetails>()})
+      return genFunctionType(*procDetails);
+
+    // Use association. Need to get to the ultimate definition.
+    if (auto procDetails{proc->detailsIf<UseDetails>()}) {
+      auto sym{procDetails->symbol()};
+      for (; sym.detailsIf<UseDetails>();)
+        sym = sym.detailsIf<UseDetails>()->symbol();
+      if (auto pd{sym.detailsIf<SubprogramDetails>()})
+        return genFunctionType(*pd);
+    }
+    fir::emitFatalError(loc, "Procedure pointer error.");
+  }
+
+  mlir::FunctionType genFunctionType(const SubprogramDetails &details) {
+    llvm::SmallVector<mlir::Type> resTys;
+    llvm::SmallVector<mlir::Type> argTys;
+    if (details.isFunction())
+      resTys.emplace_back(genSymbolType(details.result()));
+    for (auto args : details.dummyArgs())
+      if (args->attrs().test(Fortran::semantics::Attr::VALUE))
+        argTys.emplace_back(genSymbolType(*args));
+      else
+        argTys.emplace_back(fir::ReferenceType::get(genSymbolType(*args)));
----------------
jeanPerier wrote:

The reality is much more complex (arguments may be descriptor, BIND(C) changes things, we may still pass VALUE attributes in memory....). You should plug into the code that lowers procedure interface (CallInterface.h) by using [translateSignature](https://github.com/llvm/llvm-project/blob/3e32b809001cf3a9d6f9cea4030fb9fe66f083f2/flang/include/flang/Lower/CallInterface.h#L418C1-L418C19).

In fact, you can likely simply replace most of the changes here by:
````
if (Fortran::semantics::IsProcedurePointer(ultimate)) {
  Fortran::evaluate::ProcedureDesignator proc(ultimate);
  return Fortran::lower::translateSignature(proc, converter);
}
````

https://github.com/llvm/llvm-project/pull/70461


More information about the flang-commits mailing list