[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 6 10:25:51 PST 2023


================
@@ -3224,8 +3224,13 @@ class FirConverter : public Fortran::lower::AbstractConverter {
       mlir::Location loc, const Fortran::evaluate::Assignment &assign,
       const Fortran::evaluate::Assignment::BoundsSpec &lbExprs) {
     Fortran::lower::StatementContext stmtCtx;
-    if (Fortran::evaluate::IsProcedure(assign.rhs))
-      TODO(loc, "procedure pointer assignment");
+
+    if (Fortran::evaluate::IsProcedure(assign.rhs)) {
+      auto lhs{fir::getBase(genExprAddr(assign.lhs, stmtCtx, &loc))};
+      auto rhs{fir::getBase(genExprAddr(assign.rhs, stmtCtx, &loc))};
----------------
jeanPerier wrote:

Ok, makes sense to me, but I still think you may need to do something here to deal with pointer procedure RHS, or that a TODO should be added to prevent a crash when compiling:

```
  interface
    real function iface()
    end function
  end interface
  procedure(iface), pointer :: p1, p2
  p1 => p2
end
```

Note that if you update hlfir::derefPointersAndAllocatables, then you should also have logic on the HLFIR only path:
```
hlfir::Entity lhs = Fortran::lower::convertExprToHLFIR(
          loc, *this, assign.lhs, localSymbols, stmtCtx);
hlfir::Entity rhs = Fortran::lower::convertExprToHLFIR(
          loc, *this, assign.rhs, localSymbols, stmtCtx);
rhs = hlfir::derefPointersAndAllocatables(loc, builder, rhs);
builder.createStoreWithConvert(loc, rhs, lhs);
```

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


More information about the flang-commits mailing list