@@ -79,8 +79,14 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
79
79
llvm::SmallVector<mlir::Type, 8 > inMembers;
80
80
tuple.getFlattenedTypes (inMembers);
81
81
llvm::SmallVector<mlir::Type, 8 > members;
82
- for (auto mem : inMembers)
83
- members.push_back (convertType (mem).cast <mlir::Type>());
82
+ for (auto mem : inMembers) {
83
+ // Prevent fir.box from degenerating to a pointer to a descriptor in the
84
+ // context of a tuple type.
85
+ if (auto box = mem.dyn_cast <fir::BoxType>())
86
+ members.push_back (convertBoxTypeAsStruct (box));
87
+ else
88
+ members.push_back (convertType (mem).cast <mlir::Type>());
89
+ }
84
90
return mlir::LLVM::LLVMStructType::getLiteral (&getContext (), members,
85
91
/* isPacked=*/ false );
86
92
});
@@ -171,6 +177,13 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
171
177
mlir::LLVM::LLVMStructType::getLiteral (&getContext (), parts,
172
178
/* isPacked=*/ false ));
173
179
}
180
+ // / Convert fir.box type to the corresponding llvm struct type instead of a
181
+ // / pointer to this struct type.
182
+ mlir::Type convertBoxTypeAsStruct (BoxType box) {
183
+ return convertBoxType (box)
184
+ .cast <mlir::LLVM::LLVMPointerType>()
185
+ .getElementType ();
186
+ }
174
187
175
188
// fir.boxproc<any> --> llvm<"{ any*, i8* }">
176
189
mlir::Type convertBoxProcType (BoxProcType boxproc) {
@@ -269,8 +282,14 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
269
282
auto st = mlir::LLVM::LLVMStructType::getIdentified (&getContext (), name);
270
283
identStructCache[name] = st;
271
284
llvm::SmallVector<mlir::Type, 8 > members;
272
- for (auto mem : derived.getTypeList ())
273
- members.push_back (convertType (mem.second ).cast <mlir::Type>());
285
+ for (auto mem : derived.getTypeList ()) {
286
+ // Prevent fir.box from degenerating to a pointer to a descriptor in the
287
+ // context of a record type.
288
+ if (auto box = mem.second .dyn_cast <fir::BoxType>())
289
+ members.push_back (convertBoxTypeAsStruct (box));
290
+ else
291
+ members.push_back (convertType (mem.second ).cast <mlir::Type>());
292
+ }
274
293
(void )st.setBody (members, /* isPacked=*/ false );
275
294
return st;
276
295
}
0 commit comments