diff --git a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp index 54892ef99bf58..434973f5887e8 100644 --- a/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp +++ b/flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp @@ -805,13 +805,12 @@ llvm::LogicalResult BroadcastAssignBufferization::matchAndRewrite( shape, /*slice=*/mlir::Value{}); } else { // Array references must have fixed shape, when used in assignments. + auto refTy = mlir::cast(lhs.getType()); + auto seqTy = mlir::cast(refTy.getElementType()); + llvm::ArrayRef fixedShape = seqTy.getShape(); int64_t flatExtent = 1; - for (const mlir::Value &extent : extents) { - mlir::Operation *op = extent.getDefiningOp(); - assert(op && "no defining operation for constant array extent"); - flatExtent *= fir::toInt(mlir::cast(*op)); - } - + for (int64_t extent : fixedShape) + flatExtent *= extent; flatArrayType = fir::ReferenceType::get(fir::SequenceType::get({flatExtent}, eleTy)); flatArray = builder.createConvert(loc, flatArrayType, flatArray); diff --git a/flang/test/HLFIR/opt-scalar-assign.fir b/flang/test/HLFIR/opt-scalar-assign.fir index 74cdcd9622adb..468a5dbf988d7 100644 --- a/flang/test/HLFIR/opt-scalar-assign.fir +++ b/flang/test/HLFIR/opt-scalar-assign.fir @@ -155,3 +155,32 @@ func.func @_QPtest6(%arg0: !fir.ref>>> {f // CHECK: } // CHECK: return // CHECK: } + +func.func @_QQmain() { + return +} + +func.func private @_QFPtest7(%arg0: !fir.ref>>> {fir.host_assoc}) attributes {fir.host_symbol = @_QQmain, llvm.linkage = #llvm.linkage} { + %0 = fir.dummy_scope : !fir.dscope + %c0_i32 = arith.constant 0 : i32 + %1 = fir.coordinate_of %arg0, %c0_i32 : (!fir.ref>>>, i32) -> !fir.ref>> + %2 = fir.load %1 : !fir.ref>> + %3 = fir.box_addr %2 : (!fir.box>) -> !fir.ref> + %c0 = arith.constant 0 : index + %4:3 = fir.box_dims %2, %c0 : (!fir.box>, index) -> (index, index, index) + %c1 = arith.constant 1 : index + %5:3 = fir.box_dims %2, %c1 : (!fir.box>, index) -> (index, index, index) + %6 = fir.shape %4#1, %5#1 : (index, index) -> !fir.shape<2> + %7:2 = hlfir.declare %3(%6) {fortran_attrs = #fir.var_attrs, uniq_name = "_QFEa"} : (!fir.ref>, !fir.shape<2>) -> (!fir.ref>, !fir.ref>) + %c0_i32_0 = arith.constant 0 : i32 + hlfir.assign %c0_i32_0 to %7#0 : i32, !fir.ref> + return +} + +// CHECK-LABEL: func.func private @_QFPtest7({{.*}}) {{.*}} { +// CHECK: %[[VAL_0:.*]] = arith.constant 0 : i32 +// CHECK: fir.do_loop %[[VAL_1:.*]] = %{{.*}} to %{{.*}} step %{{.*}} unordered { +// CHECK: %[[VAL_2:.*]] = hlfir.designate %{{.*}} (%[[VAL_1]]) : (!fir.ref>, index) -> !fir.ref +// CHECK: hlfir.assign %[[VAL_0]] to %[[VAL_2]] : i32, !fir.ref +// CHECK: } +// CHECK: }