Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,16 @@ struct AssociateOpConversion
!mlir::isa<fir::BaseBoxType>(assocType)) ||
((mlir::isa<fir::BoxCharType>(sourceVar.getType()) &&
!mlir::isa<fir::BoxCharType>(assocType)))) {
sourceVar =
fir::BoxAddrOp::create(builder, loc, assocType, sourceVar);
sourceVar = builder.create<fir::BoxAddrOp>(loc, assocType, sourceVar);
} else if (mlir::isa<fir::ReferenceType>(sourceVar.getType()) &&
mlir::isa<fir::BoxCharType>(assocType)) {
mlir::Value lenVal = associate.getTypeparams()[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please assert that getTypeparams() returns a vector of length one.

auto refTy = mlir::cast<fir::ReferenceType>(sourceVar.getType());
auto charTy = mlir::cast<fir::CharacterType>(refTy.getEleTy());
auto boxCharType =
fir::BoxCharType::get(builder.getContext(), charTy.getFKind());
sourceVar = builder.create<fir::EmboxCharOp>(loc, boxCharType,
sourceVar, lenVal);
} else {
sourceVar = builder.createConvert(loc, assocType, sourceVar);
}
Expand Down
16 changes: 16 additions & 0 deletions flang/test/Lower/adjustr.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
! RUN: %flang_fc1 -emit-fir -o - %s | FileCheck %s

! Checking no reference to boxchar conversion is in the emitted fir.
! CHECK-NOT: (!fir.ref<!fir.char<1,4>>) -> !fir.boxchar<1>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the checks to show what kind of emboxchar we generate after this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added check for the emboxchar that is generated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add more context into the checks, e.g. the operands of fir.emboxchar, where they are coming from, and how the results of fir.emboxchar are used.

! CHECK: %[[Const4:.*]] = arith.constant 4 : index
! CHECK: fir.emboxchar

program main
logical ,dimension(1):: mask = .true.
character(len=2),dimension(1):: d1 = "a "
character(len=4),dimension(1):: d4
where (mask)
d4 = adjustr(d1 // d1)
end where
write(6,*) "d4 =", d4
end