[flang-commits] [flang] [Flang]: Lowering reference to functions that return a procedure pointer (PR #78194)

via flang-commits flang-commits at lists.llvm.org
Thu Jan 18 05:21:44 PST 2024


================
@@ -1425,9 +1425,14 @@ class HlfirBuilder {
   }
 
   hlfir::EntityWithAttributes gen(const Fortran::evaluate::ProcedureRef &expr) {
-    TODO(
-        getLoc(),
-        "lowering function references that return procedure pointers to HLFIR");
+    fir::FirOpBuilder &builder = getBuilder();
+    Fortran::evaluate::ProcedureDesignator proc{expr.proc()};
+    auto procTy{Fortran::lower::translateSignature(proc, getConverter())};
+    mlir::Type resType = fir::BoxProcType::get(builder.getContext(), procTy);
----------------
jeanPerier wrote:

I am not convinced that resType is correct here.

I would expect resType to be something like `procTy.getResult(0)``, I am wondering if the current code isn't creating a `fir.boxproc<(ArgsX) -> (fir.boxproc((R) -> (ArgsY, ...)))>` instead of `fir.boxproc((R) -> (ArgsY, ...))`.

I think this makes little functional difference currently given resType is not used to generate IR (just to check if it is a fir::BoxProcType, which is true in both case), but could you check that recType is the expected `fir.boxproc((R) -> (ArgsY, ...))` here to avoid future bugs?

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


More information about the flang-commits mailing list