diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -5476,9 +5476,12 @@ CC genarr(const Fortran::evaluate::SetLength &x) { auto lf = genarr(x.left()); mlir::Value rhs = fir::getBase(asScalar(x.right())); - return [=](IterSpace iters) -> ExtValue { - mlir::Value lhs = fir::getBase(lf(iters)); - return fir::CharBoxValue{lhs, rhs}; + fir::factory::CharacterExprHelper charHelper(builder, getLoc()); + return [=, &charHelper](IterSpace iters) -> ExtValue { + fir::CharBoxValue temp = charHelper.createCharacterTemp( + charHelper.getCharacterType(fir::getBase(lf(iters)).getType()), rhs); + charHelper.createAssign(temp, lf(iters)); + return temp; }; } diff --git a/flang/test/Lower/array-expression.f90 b/flang/test/Lower/array-expression.f90 --- a/flang/test/Lower/array-expression.f90 +++ b/flang/test/Lower/array-expression.f90 @@ -998,6 +998,7 @@ ! CHECK: %[[VAL_28:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_29:.*]] = arith.subi %[[VAL_13]], %[[VAL_27]] : index ! CHECK: %[[VAL_30:.*]] = fir.do_loop %[[VAL_31:.*]] = %[[VAL_28]] to %[[VAL_29]] step %[[VAL_27]] unordered iter_args(%[[VAL_32:.*]] = %[[VAL_15]]) -> (!fir.array<70x!fir.char<4,?>>) { +! CHECK: %[[char_temp:.*]] = fir.alloca !fir.char<4,?>(%16 : i64) {bindc_name = ".chrtmp"} ! CHECK: %[[VAL_33:.*]] = fir.array_access %[[VAL_24]], %[[VAL_31]] : (!fir.array<140x!fir.char<2,13>>, index) -> !fir.ref> ! CHECK: %[[VAL_34:.*]] = fir.alloca !fir.char<4,?>(%[[VAL_4]] : index) ! CHECK: %[[VAL_35:.*]] = arith.cmpi slt, %[[VAL_4]], %[[VAL_4]] : index @@ -1024,7 +1025,7 @@ ! CHECK: %[[VAL_53:.*]] = arith.muli %[[VAL_51]], %[[VAL_52]] : i64 ! CHECK: %[[VAL_54:.*]] = arith.constant false ! CHECK: %[[VAL_55:.*]] = fir.convert %[[VAL_46]] : (!fir.ref>) -> !fir.ref -! CHECK: %[[VAL_56:.*]] = fir.convert %[[VAL_34]] : (!fir.ref>) -> !fir.ref +! CHECK: %[[VAL_56:.*]] = fir.convert %[[char_temp]] : (!fir.ref>) -> !fir.ref ! CHECK: fir.call @llvm.memmove.p0.p0.i64(%[[VAL_55]], %[[VAL_56]], %[[VAL_53]], %[[VAL_54]]) : (!fir.ref, !fir.ref, i64, i1) -> () ! CHECK: %[[VAL_57:.*]] = arith.constant 1 : i32 ! CHECK: %[[VAL_58:.*]] = arith.subi %[[VAL_11]], %[[VAL_57]] : i32 diff --git a/flang/test/Lower/structure-constructors.f90 b/flang/test/Lower/structure-constructors.f90 --- a/flang/test/Lower/structure-constructors.f90 +++ b/flang/test/Lower/structure-constructors.f90 @@ -105,6 +105,7 @@ ! CHECK: %[[VAL_18:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_19:.*]] = arith.subi %[[VAL_12]], %[[VAL_17]] : index ! CHECK: %[[VAL_20:.*]] = fir.do_loop %[[VAL_21:.*]] = %[[VAL_18]] to %[[VAL_19]] step %[[VAL_17]] unordered iter_args(%[[VAL_22:.*]] = %[[VAL_14]]) -> (!fir.array<5x!fir.char<1,3>>) { + ! CHECK: %[[char_temp:.*]] = fir.alloca !fir.char<1,3> {bindc_name = ".chrtmp"} ! CHECK: %[[VAL_23:.*]] = fir.array_access %[[VAL_16]], %[[VAL_21]] : (!fir.array<5x!fir.char<1,3>>, index) -> !fir.ref> ! CHECK: %[[VAL_24:.*]] = fir.array_access %[[VAL_22]], %[[VAL_21]] : (!fir.array<5x!fir.char<1,3>>, index) -> !fir.ref> ! CHECK: %[[VAL_25:.*]] = arith.constant 3 : index @@ -113,7 +114,7 @@ ! CHECK: %[[VAL_28:.*]] = arith.muli %[[VAL_26]], %[[VAL_27]] : i64 ! CHECK: %[[VAL_29:.*]] = arith.constant false ! CHECK: %[[VAL_30:.*]] = fir.convert %[[VAL_24]] : (!fir.ref>) -> !fir.ref - ! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_23]] : (!fir.ref>) -> !fir.ref + ! CHECK: %[[VAL_31:.*]] = fir.convert %[[char_temp]] : (!fir.ref>) -> !fir.ref ! CHECK: fir.call @llvm.memmove.p0.p0.i64(%[[VAL_30]], %[[VAL_31]], %[[VAL_28]], %[[VAL_29]]) : (!fir.ref, !fir.ref, i64, i1) -> () ! CHECK: %[[VAL_32:.*]] = fir.array_amend %[[VAL_22]], %[[VAL_24]] : (!fir.array<5x!fir.char<1,3>>, !fir.ref>) -> !fir.array<5x!fir.char<1,3>> ! CHECK: fir.result %[[VAL_32]] : !fir.array<5x!fir.char<1,3>>