Skip to content

Commit 4f86344

Browse files
committed
Create emboxchar
1 parent ae2f94c commit 4f86344

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,17 @@ struct AssociateOpConversion
446446
((mlir::isa<fir::BoxCharType>(sourceVar.getType()) &&
447447
!mlir::isa<fir::BoxCharType>(assocType)))) {
448448
sourceVar = builder.create<fir::BoxAddrOp>(loc, assocType, sourceVar);
449-
} else if (!mlir::isa<fir::ReferenceType>(sourceVar.getType()) ||
450-
!mlir::isa<fir::BoxCharType>(assocType)) {
449+
} else if (mlir::isa<fir::ReferenceType>(sourceVar.getType()) &&
450+
mlir::isa<fir::BoxCharType>(assocType)) {
451+
auto refTy = mlir::cast<fir::ReferenceType>(sourceVar.getType());
452+
auto charTy = mlir::dyn_cast<fir::CharacterType>(refTy.getEleTy());
453+
mlir::Value lenVal = builder.createIntegerConstant(
454+
loc, builder.getCharacterLengthType(), charTy.getLen());
455+
auto boxCharType =
456+
fir::BoxCharType::get(builder.getContext(), charTy.getFKind());
457+
sourceVar = builder.create<fir::EmboxCharOp>(loc, boxCharType,
458+
sourceVar, lenVal);
459+
} else {
451460
sourceVar = builder.createConvert(loc, assocType, sourceVar);
452461
}
453462
return sourceVar;

0 commit comments

Comments
 (0)