diff --git a/flang/lib/Optimizer/CodeGen/Target.h b/flang/lib/Optimizer/CodeGen/Target.h --- a/flang/lib/Optimizer/CodeGen/Target.h +++ b/flang/lib/Optimizer/CodeGen/Target.h @@ -77,6 +77,9 @@ /// value may need to be converted to a hidden reference argument. virtual Marshalling complexReturnType(mlir::Type eleTy) const = 0; + /// Type presentation of a `boxchar` type value in memory. + virtual mlir::Type boxcharMemoryType(mlir::Type eleTy) const = 0; + /// Type representation of a `boxchar` type argument when passed by value. /// An argument value may need to be passed as a (safe) reference argument. /// diff --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp --- a/flang/lib/Optimizer/CodeGen/Target.cpp +++ b/flang/lib/Optimizer/CodeGen/Target.cpp @@ -42,6 +42,14 @@ return mlir::TupleType::get(eleTy.getContext(), range); } + mlir::Type boxcharMemoryType(mlir::Type eleTy) const override { + auto idxTy = mlir::IntegerType::get(eleTy.getContext(), S::defaultWidth); + auto ptrTy = fir::ReferenceType::get(eleTy); + // { t*, index } + mlir::TypeRange range = {ptrTy, idxTy}; + return mlir::TupleType::get(eleTy.getContext(), range); + } + Marshalling boxcharArgumentType(mlir::Type eleTy, bool sret) const override { CodeGenSpecifics::Marshalling marshal; auto idxTy = mlir::IntegerType::get(eleTy.getContext(), S::defaultWidth); diff --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h --- a/flang/lib/Optimizer/CodeGen/TypeConverter.h +++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h @@ -50,6 +50,10 @@ // Each conversion should return a value of type mlir::Type. addConversion([&](BoxType box) { return convertBoxType(box); }); + addConversion([&](BoxCharType boxchar) { + LLVM_DEBUG(llvm::dbgs() << "type convert: " << boxchar << '\n'); + return convertType(specifics->boxcharMemoryType(boxchar.getEleTy())); + }); addConversion( [&](fir::CharacterType charTy) { return convertCharType(charTy); }); addConversion([&](fir::LogicalType boolTy) { diff --git a/flang/test/Fir/types-to-llvm.fir b/flang/test/Fir/types-to-llvm.fir --- a/flang/test/Fir/types-to-llvm.fir +++ b/flang/test/Fir/types-to-llvm.fir @@ -203,3 +203,15 @@ func private @foo16(%arg0: !fir.vector<2:!fir.real<16>>) // CHECK-LABEL: foo16 // CHECK-SAME: vector<2xf128> + +// ----- + +// Test `!fir.boxchar` conversion + +func private @foo0(%arg0: !fir.boxchar<1>) +// CHECK-LABEL: foo0 +// CHECK-SAME: !llvm.struct<(ptr, i64)> + +func private @foo1(%arg0: !fir.boxchar<2>) +// CHECK-LABEL: foo1 +// CHECK-SAME: !llvm.struct<(ptr, i64)>