diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -929,7 +929,10 @@ if (auto seqTy = mlir::dyn_cast(reductionTy)) reductionTy = seqTy.getEleTy(); - if (!fir::isa_trivial(reductionTy)) + if (!fir::isa_trivial(reductionTy) && + ((fir::isAllocatableType(reductionTy) || + fir::isPointerType(reductionTy)) && + !bounds.empty())) TODO(operandLocation, "reduction with unsupported type"); auto op = createDataEntryOp( diff --git a/flang/test/Lower/OpenACC/acc-reduction.f90 b/flang/test/Lower/OpenACC/acc-reduction.f90 --- a/flang/test/Lower/OpenACC/acc-reduction.f90 +++ b/flang/test/Lower/OpenACC/acc-reduction.f90 @@ -777,3 +777,30 @@ ! CHECK-LABEL: func.func @_QPacc_reduction_mul_cmplx() ! CHECK: %[[RED:.*]] = acc.reduction varPtr(%{{.*}} : !fir.ref>) -> !fir.ref> {name = "c"} ! CHECK: acc.parallel reduction(@reduction_mul_z32 -> %[[RED]] : !fir.ref>) + +subroutine acc_reduction_add_alloc() + integer, allocatable :: i + allocate(i) + !$acc parallel reduction(+:i) + !$acc end parallel +end subroutine + +! CHECK-LABEL: func.func @_QPacc_reduction_add_alloc() +! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.box> {bindc_name = "i", uniq_name = "_QFacc_reduction_add_allocEi"} +! CHECK: %[[LOAD:.*]] = fir.load %[[ALLOCA]] : !fir.ref>> +! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] : (!fir.box>) -> !fir.heap +! CHECK: %[[RED:.*]] = acc.reduction varPtr(%[[BOX_ADDR]] : !fir.heap) -> !fir.heap {name = "i"} +! CHECK: acc.parallel reduction(@reduction_add_i32 -> %[[RED]] : !fir.heap) + +subroutine acc_reduction_add_pointer(i) + integer, pointer :: i + !$acc parallel reduction(+:i) + !$acc end parallel +end subroutine + +! CHECK-LABEL: func.func @_QPacc_reduction_add_pointer( +! CHECK-SAME: %[[ARG0:.*]]: !fir.ref>> {fir.bindc_name = "i"}) +! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref>> +! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[LOAD]] : (!fir.box>) -> !fir.ptr +! CHECK: %[[RED:.*]] = acc.reduction varPtr(%[[BOX_ADDR]] : !fir.ptr) -> !fir.ptr {name = "i"} +! CHECK: acc.parallel reduction(@reduction_add_i32 -> %[[RED]] : !fir.ptr)