[flang-commits] [flang] [flang] Add hlfir.index op to represent index intrinsic function (PR #157575)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 9 02:17:11 PDT 2025
================
@@ -3039,6 +3044,38 @@ hlfir::Entity Fortran::lower::PreparedActualArgument::getActual(
return hlfir::Entity{addr};
}
+mlir::Value Fortran::lower::PreparedActualArgument::getOptionalValue(
+ mlir::Location loc, fir::FirOpBuilder &builder) const {
+ mlir::Type eleType;
+ if (auto *actualEntity = std::get_if<hlfir::Entity>(&actual))
+ eleType = hlfir::getFortranElementType(actualEntity->getType());
+ else
+ TODO(loc, "compute element type from hlfir::ElementalAddrOp");
+
+ // For an elemental call, getActual() may produce
+ // a designator denoting the array element to be passed
+ // to the subprogram. If the actual array is dynamically
+ // optional the designator must be generated under
+ // isPresent check (see also genIntrinsicRefCore).
+ return builder
+ .genIfOp(loc, {eleType}, getIsPresent(),
+ /*withElseRegion=*/true)
+ .genThen([&]() {
+ hlfir::Entity actual = getActual(loc, builder);
----------------
jeanPerier wrote:
Thanks for finding and fixing this bug!
https://github.com/llvm/llvm-project/pull/157575
More information about the flang-commits
mailing list