[flang-commits] [flang] [llvm] [flang] Guard absent optional operands in elemental character MIN/MAX (PR #191244)

via flang-commits flang-commits at lists.llvm.org
Fri Apr 10 08:46:17 PDT 2026


================
@@ -465,7 +465,55 @@ mlir::Value HlfirCharExtremumLowering::lowerImpl(
     const Fortran::lower::PreparedActualArguments &loweredActuals,
     const fir::IntrinsicArgumentLoweringRules *argLowering,
     mlir::Type stmtResultType) {
-  auto operands = getOperandVector(loweredActuals, argLowering);
+  // Check whether any argument is dynamically optional.  When an optional
----------------
jeanPerier wrote:

I think the fact that the code is reaching this is showing some kind of issues in the dispatching inside ConvertCall.cpp.

For scalars, such optional case is hitting a TODO `lib/Lower/CustomIntrinsicCall.cpp:122: not yet implemented: CHARACTER MIN and MAX with dynamically optional arguments`.

So this TODO should also have been hit inside the kernel.

I think the issue is that `genCustomIntrinsicRefCore` [here ](https://github.com/llvm/llvm-project/blob/aeda856d2fafcbc969979abfb88010ce0fe90452/flang/lib/Lower/ConvertCall.cpp#L2160)is being bypassed by `genHLFIRIntrinsicRefCore` while it is being handled before the HLFIR intrinsic case [in genIntrinsicRef here](https://github.com/llvm/llvm-project/blob/aeda856d2fafcbc969979abfb88010ce0fe90452/flang/lib/Lower/ConvertCall.cpp#L3088).

You may break a few legacy tests, but I think the `genCustomIntrinsicRefCore` should be moved at the beginning of `genHLFIRIntrinsicRefCore` for symmetry.

Then we can decide if hlfir.char_extremum should deal with OPTIONAL arguments. 

https://github.com/llvm/llvm-project/pull/191244


More information about the flang-commits mailing list