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

via flang-commits flang-commits at lists.llvm.org
Mon Nov 13 10:52:41 PST 2023


================
@@ -125,3 +130,15 @@ hlfir::EntityWithAttributes Fortran::lower::convertProcedureDesignatorToHLFIR(
       [funcAddr](const auto &) { return funcAddr; });
   return hlfir::EntityWithAttributes{res};
 }
+
+mlir::Value Fortran::lower::convertProcedureDesignatorToAddress(
+    Fortran::lower::AbstractConverter &converter, mlir::Location loc,
+    mlir::Type boxType, Fortran::lower::StatementContext &stmtCtx,
+    const Fortran::semantics::Symbol *sym) {
+  Fortran::lower::SymMap globalOpSymMap;
+  Fortran::evaluate::ProcedureDesignator proc(*sym);
+  auto procVal{Fortran::lower::convertProcedureDesignatorToHLFIR(
+      loc, converter, proc, globalOpSymMap, stmtCtx)};
+  return fir::getBase(Fortran::lower::convertToAddress(
+      loc, converter, procVal, stmtCtx, procVal.getType()));
----------------
jeanPerier wrote:

I am afraid we may hit verifier errors in some cases (I need to find a convincing example). The HasValueOp operand must have the same type as the fir.globalOp.

- The fir.globalOp takes its type from the procedure pointer interface
- The type of `procVal` passed later to HasValueOp is from sym whose type is from the interface of the intial target.

If for any reasons the interfaces of the procedure pointer and its initial targets are compatible "green light from semantics" but do not lower to the exact same MLIR signature, this will be a bug here. I am not convinced we should rely on the MLIR types always being the same, even though I do not have an immediate Fortran example that I can come up with.

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


More information about the flang-commits mailing list