[flang-commits] [flang] [Flang] Add a HLFIR Minloc intrinsic (PR #74436)

via flang-commits flang-commits at lists.llvm.org
Tue Dec 5 02:04:33 PST 2023


================
@@ -206,6 +219,8 @@ llvm::SmallVector<mlir::Value> HlfirTransformationalIntrinsic::getOperandVector(
       else if (!argRules.handleDynamicOptional &&
                argRules.lowerAs != fir::LowerIntrinsicArgAs::Inquired)
         valArg = hlfir::derefPointersAndAllocatables(loc, builder, actual);
+      else if (argRules.lowerAs == fir::LowerIntrinsicArgAs::Value)
----------------
jeanPerier wrote:

You should protect this with `!argRules.handleDynamicOptional &&`, otherwise, this will unconditionally dereference arguments that are could be absent optional... which is the case of BACK.

The following code is legal:
````
module m
contains
subroutine test(array, back, mask)
   integer :: array(2, 2)
   logical, optional :: back
   logical, optional :: mask(2, 2)
   print *, "got   :", minloc(array, back=back, mask=mask)
end subroutine
end module

  use m
  integer :: array(2,2) = reshape([1,2,2,1], shape=[2,2])
  logical :: mask(2,2) = reshape([.False., .True., .True., .False.], shape=[2,2])
  logical :: back = .True.
  print *, "expect:", [1,1]
  call test(array)
  print *, "expect:", [1,2]
  call test(array, back, mask)
  print *, "expect:", [2,1]
  call test(array, back=NULL(), mask=mask)
  print *, "expect:", [2,2]
  call test(array, back)
end
````

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


More information about the flang-commits mailing list