@@ -417,27 +417,35 @@ class MutablePropertyWriter {
417
417
// Ignore lengths if already constant in the box type (this would trigger an
418
418
// error in the embox).
419
419
llvm::SmallVector<mlir::Value> cleanedLengths;
420
- auto cleanedAddr = addr;
421
- if (auto charTy = box.getEleTy ().dyn_cast <fir::CharacterType>()) {
422
- // Cast address to box type so that both input and output type have
423
- // unknown or constant lengths.
424
- auto bt = box.getBaseTy ();
425
- auto addrTy = addr.getType ();
426
- auto type = addrTy.isa <fir::HeapType>() ? fir::HeapType::get (bt)
427
- : addrTy.isa <fir::PointerType>()
428
- ? fir::PointerType::get (bt)
429
- : builder.getRefType (bt);
430
- cleanedAddr = builder.createConvert (loc, type, addr);
431
- if (charTy.getLen () == fir::CharacterType::unknownLen ())
432
- cleanedLengths.append (lengths.begin (), lengths.end ());
433
- } else if (box.isDerivedWithLengthParameters ()) {
434
- TODO (loc, " updating mutablebox of derived type with length parameters" );
435
- cleanedLengths = lengths;
420
+ mlir::Value irBox;
421
+ if (addr.getType ().isa <fir::BoxType>()) {
422
+ // The entity is already boxed.
423
+ irBox = builder.createConvert (loc, box.getBoxTy (), addr);
424
+ } else {
425
+ auto cleanedAddr = addr;
426
+ if (auto charTy = box.getEleTy ().dyn_cast <fir::CharacterType>()) {
427
+ // Cast address to box type so that both input and output type have
428
+ // unknown or constant lengths.
429
+ auto bt = box.getBaseTy ();
430
+ auto addrTy = addr.getType ();
431
+ auto type = addrTy.isa <fir::HeapType>()
432
+ ? fir::HeapType::get (bt)
433
+ : addrTy.isa <fir::PointerType>()
434
+ ? fir::PointerType::get (bt)
435
+ : builder.getRefType (bt);
436
+ cleanedAddr = builder.createConvert (loc, type, addr);
437
+ if (charTy.getLen () == fir::CharacterType::unknownLen ())
438
+ cleanedLengths.append (lengths.begin (), lengths.end ());
439
+ } else if (box.isDerivedWithLengthParameters ()) {
440
+ TODO (loc, " updating mutablebox of derived type with length parameters" );
441
+ cleanedLengths = lengths;
442
+ }
443
+ irBox = builder.create <fir::EmboxOp>(loc, box.getBoxTy (), cleanedAddr,
444
+ shape, emptySlice, cleanedLengths);
436
445
}
437
- auto irBox = builder.create <fir::EmboxOp>(
438
- loc, box.getBoxTy (), cleanedAddr, shape, emptySlice, cleanedLengths);
439
446
builder.create <fir::StoreOp>(loc, irBox, box.getAddr ());
440
447
}
448
+
441
449
// / Update the set of property variables of the MutableBoxValue.
442
450
void updateMutableProperties (mlir::Value addr, mlir::ValueRange lbounds,
443
451
mlir::ValueRange extents,
0 commit comments