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

Daniel Chen via flang-commits flang-commits at lists.llvm.org
Fri Oct 27 14:00:23 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)));
----------------
DanielCChen wrote:

Thanks! This works! Will replace the code.

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


More information about the flang-commits mailing list