Skip to content

Commit 6af6577

Browse files
committed
fix fm203
1 parent e3e7b0f commit 6af6577

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
13781378
if (isCharacterCategory(lhsType->category())) {
13791379
// Fortran 2018 10.2.1.3 p10 and p11
13801380
// Generating value for lhs to get fir.boxchar.
1381-
auto lhs = genExprValue(assign.lhs);
1381+
auto lhs = genExprAddr(assign.lhs);
13821382
auto rhs = genExprValue(assign.rhs);
13831383
Fortran::lower::CharacterExprHelper{*builder, loc}.createAssign(
13841384
lhs, rhs);

flang/lib/Lower/CharacterExpr.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,15 @@ Fortran::lower::CharacterExprHelper::createEmbox(const fir::CharBoxValue &box) {
145145
auto boxCharType = fir::BoxCharType::get(builder.getContext(), kind);
146146
auto refType = getReferenceType(str);
147147
// So far, fir.emboxChar fails lowering to llvm when it is given
148-
// fir.data<fir.array<len x fir.char<kind>>> types, so convert to
149-
// fir.data<fir.char<kind>> if needed.
148+
// fir.ref<fir.array<len x fir.char<kind>>> types, so convert to
149+
// fir.ref<fir.char<kind>> if needed.
150150
auto buff = str.getBuffer();
151-
if (refType != str.getBuffer().getType())
152-
buff = builder.createConvert(loc, refType, buff);
151+
buff = builder.createConvert(loc, refType, buff);
153152
// Convert in case the provided length is not of the integer type that must
154153
// be used in boxchar.
155154
auto lenType = getLengthType();
156155
auto len = str.getLen();
157-
if (str.getLen().getType() != lenType)
158-
len = builder.createConvert(loc, lenType, len);
156+
len = builder.createConvert(loc, lenType, len);
159157
return builder.create<fir::EmboxCharOp>(loc, boxCharType, buff, len);
160158
}
161159

@@ -212,16 +210,20 @@ Fortran::lower::CharacterExprHelper::createTemp(mlir::Type type,
212210
void Fortran::lower::CharacterExprHelper::createLengthOneAssign(
213211
const fir::CharBoxValue &lhs, const fir::CharBoxValue &rhs) {
214212
auto addr = lhs.getBuffer();
215-
auto refType = getReferenceType(lhs);
216-
addr = builder.createConvert(loc, refType, addr);
217-
218213
auto val = rhs.getBuffer();
219-
if (!needToMaterialize(rhs)) {
220-
mlir::Value rhsAddr = rhs.getBuffer();
221-
rhsAddr = builder.createConvert(loc, refType, rhsAddr);
222-
val = builder.create<fir::LoadOp>(loc, rhsAddr);
214+
// If rhs value resides in memory, load it.
215+
if (!needToMaterialize(rhs))
216+
val = builder.create<fir::LoadOp>(loc, val);
217+
auto valTy = val.getType();
218+
// Precondition is rhs is size 1, but it may be wrapped in a fir.array.
219+
if (auto seqTy = valTy.dyn_cast<fir::SequenceType>()) {
220+
auto zero = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
221+
valTy = seqTy.getEleTy();
222+
val = builder.create<fir::ExtractValueOp>(loc, valTy, val, zero);
223223
}
224-
224+
auto addrTy = fir::ReferenceType::get(valTy);
225+
addr = builder.createConvert(loc, addrTy, addr);
226+
assert(fir::dyn_cast_ptrEleTy(addr.getType()) == val.getType());
225227
builder.create<fir::StoreOp>(loc, val, addr);
226228
}
227229

0 commit comments

Comments
 (0)