diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp --- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp @@ -733,7 +733,9 @@ int64_t lhsSize = lhsShape[0]; int64_t rhsSize = rhsShape[0]; - if (lhsSize != rhsSize) + constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent(); + if ((lhsSize != unknownExtent) && (rhsSize != unknownExtent) && + (lhsSize != rhsSize)) return emitOpError("both arrays must have the same size"); if (mlir::isa(lhsEleTy) != diff --git a/flang/test/Lower/HLFIR/dot_product.f90 b/flang/test/Lower/HLFIR/dot_product.f90 --- a/flang/test/Lower/HLFIR/dot_product.f90 +++ b/flang/test/Lower/HLFIR/dot_product.f90 @@ -70,3 +70,15 @@ ! CHECK-NEXT: hlfir.assign %[[PROD]] to %[[RES_VAR]]#0 : i32, !fir.ref ! CHECK-NEXT: return ! CHECK-NEXT: } + +! CHECK-LABEL: func.func @_QPdot_product5 +! CHECK: %[[LHS:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFdot_product5Elhs"} : (!fir.box>) -> (!fir.box>, !fir.box>) +! CHECK: %[[C3:.*]] = arith.constant 3 : index +! CHECK: %[[RHS_SHAPE:.*]] = fir.shape %[[C3]] : (index) -> !fir.shape<1> +! CHECK: %[[RHS:.*]]:2 = hlfir.declare %{{.*}}(%[[RHS_SHAPE]]) {uniq_name = "_QFdot_product5Erhs"} : (!fir.ref>, !fir.shape<1>) -> (!fir.ref>, !fir.ref>) +! CHECK: {{.*}} = hlfir.dot_product %[[LHS]]#0 %[[RHS]]#0 {fastmath = #arith.fastmath} : (!fir.box>, !fir.ref>) -> i32 +subroutine dot_product5(lhs, rhs, res) + integer :: lhs(:), rhs(3) + integer :: res + res = dot_product(lhs, rhs) +endsubroutine