[flang-commits] [flang] [flang] allow rebox/embox of OPTIONAL (PR #194319)
via flang-commits
flang-commits at lists.llvm.org
Mon Apr 27 04:58:40 PDT 2026
================
@@ -55,6 +57,40 @@ static void populateShift(llvm::SmallVectorImpl<mlir::Value> &vec,
vec.append(shift.getOrigins().begin(), shift.getOrigins().end());
}
+// Helper to emit embox/rebox for OPTIONAL input inside a block
+// guarded by a runtime presence check and to return an absent
+// box when the input is not present.
----------------
jeanPerier wrote:
Currently, the difference is that the codegen of a an absent fir.box is a nullptr (no descriptor at all).
So these fir.box are not safely usable (hence the conditional speculability on operation taking fir.box that checks if the input could be an OPTIONAL). This representation is required at least in the context of OPTIONAL assumed-shape in BIND(C) interface.
So at least of the rebox operations on OPTIONAL, an if/then/else logic is needed to guard the manipulation of the input. For embox, this could likely be a changed to a merge, I am mainly keeping the if/then/else to match what was currently done and to have a single logic.
https://github.com/llvm/llvm-project/pull/194319
More information about the flang-commits
mailing list