[flang-commits] [flang] [Flang] Compute elemental character MIN/MAX result length in HLFIR (PR #189464)
Sairudra More via flang-commits
flang-commits at lists.llvm.org
Wed Apr 1 04:35:48 PDT 2026
================
@@ -2758,10 +2758,37 @@ class ElementalIntrinsicCallBuilder
intrinsic->name == "merge")
return loweredActuals[0].value().genCharLength(
callContext.loc, callContext.getBuilder());
- // Character MIN/MAX is the min/max of the arguments length that are
- // present.
- TODO(callContext.loc,
- "compute elemental character min/max function result length in HLFIR");
+ // Character MIN/MAX result length is the length of the longest
+ // argument that is present.
+ assert(intrinsic &&
+ (intrinsic->name == "min" || intrinsic->name == "max") &&
+ "unexpected elemental intrinsic with character result");
+ fir::FirOpBuilder &builder = callContext.getBuilder();
+ mlir::Location loc = callContext.loc;
+ mlir::Value resultLength;
+ for (auto &preparedActual : loweredActuals) {
+ if (!preparedActual)
+ continue;
+ mlir::Value argLen = preparedActual->genCharLength(loc, builder);
----------------
Saieiei wrote:
Done!
I updated the optional handling to use fir.if, so genCharLength is only evaluated in the present branch, and I added a test for the assumed-length optional case too.
https://github.com/llvm/llvm-project/pull/189464/changes/f18a5cce4e401d838b33ce2f3c1a4621d304fbb0
https://github.com/llvm/llvm-project/pull/189464
More information about the flang-commits
mailing list