Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #917. #949

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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