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 @@ -5495,9 +5495,15 @@ CC genarr(const Fortran::evaluate::SetLength &x) { auto lf = genarr(x.left()); mlir::Value rhs = fir::getBase(asScalar(x.right())); + fir::CharBoxValue temp = + fir::factory::CharacterExprHelper(builder, getLoc()) + .createCharacterTemp( + fir::CharacterType::getUnknownLen(builder.getContext(), KIND), + rhs); return [=](IterSpace iters) -> ExtValue { - mlir::Value lhs = fir::getBase(lf(iters)); - return fir::CharBoxValue{lhs, rhs}; + fir::factory::CharacterExprHelper(builder, getLoc()) + .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 @@ -994,6 +994,7 @@ ! CHECK: %[[VAL_24:.*]] = fir.array_load %[[VAL_5]](%[[VAL_22]]) {{\[}}%[[VAL_23]]] : (!fir.ref>>, !fir.shape<1>, !fir.slice<1>) -> !fir.array<140x!fir.char<2,13>> ! CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_2]] : !fir.ref ! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i32) -> i64 +! CHECK: %[[char_temp:.*]] = fir.alloca !fir.char<4,?>(%16 : i64) {bindc_name = ".chrtmp"} ! CHECK: %[[VAL_27:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_28:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_29:.*]] = arith.subi %[[VAL_13]], %[[VAL_27]] : 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 @@ -101,6 +101,7 @@ ! CHECK: %[[VAL_14:.*]] = fir.array_load %[[VAL_11]](%[[VAL_13]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.array<5x!fir.char<1,3>> ! CHECK: %[[VAL_15:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1> ! CHECK: %[[VAL_16:.*]] = fir.array_load %[[VAL_5]](%[[VAL_15]]) : (!fir.ref>>, !fir.shape<1>) -> !fir.array<5x!fir.char<1,3>> + ! CHECK: %[[char_temp:.*]] = fir.alloca !fir.char<1,3> {bindc_name = ".chrtmp"} ! CHECK: %[[VAL_17:.*]] = arith.constant 1 : index ! CHECK: %[[VAL_18:.*]] = arith.constant 0 : index ! CHECK: %[[VAL_19:.*]] = arith.subi %[[VAL_12]], %[[VAL_17]] : 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>>