[flang-commits] [PATCH] D144743: [flang] Fix lowering of optional char proc args

Leandro Lupori via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Mar 1 14:02:21 PST 2023


luporl added inline comments.


================
Comment at: flang/lib/Optimizer/Builder/FIRBuilder.cpp:623-627
+  auto boxTy =
+      argTy.cast<mlir::TupleType>().getType(0).cast<fir::BoxProcType>();
+  mlir::Type funcTy = boxTy.getEleTy();
+  mlir::Value funcAddr = create<fir::AbsentOp>(loc, funcTy);
+  auto boxProc = create<fir::EmboxProcOp>(loc, boxTy, funcAddr);
----------------
jeanPerier wrote:
> Thinking this through a bit more, doesn't `auto boxProc = create<fir::AbsentOp>(loc, argTy.cast<mlir::TupleType>().getType(0));` works an save the EmboxProc at that level?
> I think AbsentOp should work properly on BoxProcType (otherwise, there would also be a bug for optional non character dummy procedures).
> 
> It will probably also make the extension of this code to optional character pointer procedure easier when they arrive (nothing to do other than updating the `isCharacterProcedureTuple` to detect them).
I've tried this and it works (assembly seems correct and test program runs without errors).

I'm just a bit worried about the generated FIR, that has an unconditional `fir.box_addr` on the absent BoxProc, in the `if (present(arg))` part. Is `fir.box_addr` guaranteed to work with `fir.absent` BoxProcs?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144743/new/

https://reviews.llvm.org/D144743



More information about the flang-commits mailing list