[flang-commits] [flang] [flang] allow rebox/embox of OPTIONAL (PR #194319)
via flang-commits
flang-commits at lists.llvm.org
Tue Apr 28 03:54:01 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:
> If there was a real box containing a nullptr address then I think we only need to limit speculation on fir.load (which presumably is already the case).
This could indeed be a better impl, the rational for the current implementation is that absent OPTIONAL needs to be encoded as nullptr descriptor for POINTER/ALLOCATABLE to disambiguate an absent OPTIONAL POINTER/ALLOCATABLE from a present but disassociated/unallocated one. On top of that there is the BIND(C) interface requirement to use nullptr descriptor address for OPTIONALs for things that we represent as fir.box for the SSA arguments (e.g. assumed shape), so we would need to rework the ABI representation to allow for this.
All that to say, the alternative implementation is not impossible, it is just a bit more work than switching fir.absent/fir.is_present codegen.
https://github.com/llvm/llvm-project/pull/194319
More information about the flang-commits
mailing list