Skip to content

Commit

Permalink
Merge pull request #949 from flang-compiler/ch-i917
Browse files Browse the repository at this point in the history
Fix issue #917.
  • Loading branch information
schweitzpgi authored Jul 29, 2021
2 parents 9065951 + b5bb1ef commit b209722
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions flang/lib/Lower/Allocatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,27 +417,35 @@ class MutablePropertyWriter {
// Ignore lengths if already constant in the box type (this would trigger an
// error in the embox).
llvm::SmallVector<mlir::Value> cleanedLengths;
auto cleanedAddr = addr;
if (auto charTy = box.getEleTy().dyn_cast<fir::CharacterType>()) {
// Cast address to box type so that both input and output type have
// unknown or constant lengths.
auto bt = box.getBaseTy();
auto addrTy = addr.getType();
auto type = addrTy.isa<fir::HeapType>() ? fir::HeapType::get(bt)
: addrTy.isa<fir::PointerType>()
? fir::PointerType::get(bt)
: builder.getRefType(bt);
cleanedAddr = builder.createConvert(loc, type, addr);
if (charTy.getLen() == fir::CharacterType::unknownLen())
cleanedLengths.append(lengths.begin(), lengths.end());
} else if (box.isDerivedWithLengthParameters()) {
TODO(loc, "updating mutablebox of derived type with length parameters");
cleanedLengths = lengths;
mlir::Value irBox;
if (addr.getType().isa<fir::BoxType>()) {
// The entity is already boxed.
irBox = builder.createConvert(loc, box.getBoxTy(), addr);
} else {
auto cleanedAddr = addr;
if (auto charTy = box.getEleTy().dyn_cast<fir::CharacterType>()) {
// Cast address to box type so that both input and output type have
// unknown or constant lengths.
auto bt = box.getBaseTy();
auto addrTy = addr.getType();
auto type = addrTy.isa<fir::HeapType>()
? fir::HeapType::get(bt)
: addrTy.isa<fir::PointerType>()
? fir::PointerType::get(bt)
: builder.getRefType(bt);
cleanedAddr = builder.createConvert(loc, type, addr);
if (charTy.getLen() == fir::CharacterType::unknownLen())
cleanedLengths.append(lengths.begin(), lengths.end());
} else if (box.isDerivedWithLengthParameters()) {
TODO(loc, "updating mutablebox of derived type with length parameters");
cleanedLengths = lengths;
}
irBox = builder.create<fir::EmboxOp>(loc, box.getBoxTy(), cleanedAddr,
shape, emptySlice, cleanedLengths);
}
auto irBox = builder.create<fir::EmboxOp>(
loc, box.getBoxTy(), cleanedAddr, shape, emptySlice, cleanedLengths);
builder.create<fir::StoreOp>(loc, irBox, box.getAddr());
}

/// Update the set of property variables of the MutableBoxValue.
void updateMutableProperties(mlir::Value addr, mlir::ValueRange lbounds,
mlir::ValueRange extents,
Expand Down

0 comments on commit b209722

Please sign in to comment.