@@ -61,9 +61,11 @@ DebugTypeGenerator::DebugTypeGenerator(mlir::ModuleOp m)
61
61
// descriptors like lower_bound and extent for each dimension.
62
62
mlir::Type llvmDimsType = getDescFieldTypeModel<kDimsPosInBox >()(context);
63
63
mlir::Type llvmPtrType = getDescFieldTypeModel<kAddrPosInBox >()(context);
64
+ mlir::Type llvmLenType = getDescFieldTypeModel<kElemLenPosInBox >()(context);
64
65
dimsOffset = getComponentOffset<kDimsPosInBox >(*dl, context, llvmDimsType);
65
66
dimsSize = dl->getTypeSize (llvmDimsType);
66
67
ptrSize = dl->getTypeSize (llvmPtrType);
68
+ lenOffset = getComponentOffset<kElemLenPosInBox >(*dl, context, llvmLenType);
67
69
}
68
70
69
71
static mlir::LLVM::DITypeAttr genBasicType (mlir::MLIRContext *context,
@@ -192,10 +194,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
192
194
193
195
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType (
194
196
fir::CharacterType charTy, mlir::LLVM::DIFileAttr fileAttr,
195
- mlir::LLVM::DIScopeAttr scope, mlir::Location loc) {
197
+ mlir::LLVM::DIScopeAttr scope, mlir::Location loc, bool hasDescriptor ) {
196
198
mlir::MLIRContext *context = module .getContext ();
197
- if (!charTy.hasConstantLen ())
198
- return genPlaceholderType (context);
199
199
200
200
// DWARF 5 says the following about the character encoding in 5.1.1.2.
201
201
// "DW_ATE_ASCII and DW_ATE_UCS specify encodings for the Fortran 2003
@@ -205,16 +205,38 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertCharacterType(
205
205
if (charTy.getFKind () != 1 )
206
206
encoding = llvm::dwarf::DW_ATE_UCS;
207
207
208
+ uint64_t sizeInBits = 0 ;
209
+ mlir::LLVM::DIExpressionAttr lenExpr = nullptr ;
210
+ mlir::LLVM::DIExpressionAttr locExpr = nullptr ;
211
+
212
+ if (hasDescriptor) {
213
+ llvm::SmallVector<mlir::LLVM::DIExpressionElemAttr> ops;
214
+ auto addOp = [&](unsigned opc, llvm::ArrayRef<uint64_t > vals) {
215
+ ops.push_back (mlir::LLVM::DIExpressionElemAttr::get (context, opc, vals));
216
+ };
217
+ addOp (llvm::dwarf::DW_OP_push_object_address, {});
218
+ addOp (llvm::dwarf::DW_OP_plus_uconst, {lenOffset});
219
+ lenExpr = mlir::LLVM::DIExpressionAttr::get (context, ops);
220
+ ops.clear ();
221
+
222
+ addOp (llvm::dwarf::DW_OP_push_object_address, {});
223
+ addOp (llvm::dwarf::DW_OP_deref, {});
224
+ locExpr = mlir::LLVM::DIExpressionAttr::get (context, ops);
225
+ } else if (charTy.hasConstantLen ()) {
226
+ sizeInBits =
227
+ charTy.getLen () * kindMapping.getCharacterBitsize (charTy.getFKind ());
228
+ } else {
229
+ return genPlaceholderType (context);
230
+ }
231
+
208
232
// FIXME: Currently the DIStringType in llvm does not have the option to set
209
233
// type of the underlying character. This restricts out ability to represent
210
234
// string with non-default characters. Please see issue #95440 for more
211
235
// details.
212
236
return mlir::LLVM::DIStringTypeAttr::get (
213
237
context, llvm::dwarf::DW_TAG_string_type,
214
- mlir::StringAttr::get (context, " " ),
215
- charTy.getLen () * kindMapping.getCharacterBitsize (charTy.getFKind ()),
216
- /* alignInBits=*/ 0 , /* stringLength=*/ nullptr ,
217
- /* stringLengthExp=*/ nullptr , /* stringLocationExp=*/ nullptr , encoding);
238
+ mlir::StringAttr::get (context, " " ), sizeInBits, /* alignInBits=*/ 0 ,
239
+ /* stringLength=*/ nullptr , lenExpr, locExpr, encoding);
218
240
}
219
241
220
242
mlir::LLVM::DITypeAttr DebugTypeGenerator::convertPointerLikeType (
@@ -229,6 +251,9 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertPointerLikeType(
229
251
if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(elTy))
230
252
return convertBoxedSequenceType (seqTy, fileAttr, scope, loc, genAllocated,
231
253
genAssociated);
254
+ if (auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(elTy))
255
+ return convertCharacterType (charTy, fileAttr, scope, loc,
256
+ /* hasDescriptor=*/ true );
232
257
233
258
mlir::LLVM::DITypeAttr elTyAttr = convertType (elTy, fileAttr, scope, loc);
234
259
@@ -274,7 +299,8 @@ DebugTypeGenerator::convertType(mlir::Type Ty, mlir::LLVM::DIFileAttr fileAttr,
274
299
} else if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(Ty)) {
275
300
return convertSequenceType (seqTy, fileAttr, scope, loc);
276
301
} else if (auto charTy = mlir::dyn_cast_or_null<fir::CharacterType>(Ty)) {
277
- return convertCharacterType (charTy, fileAttr, scope, loc);
302
+ return convertCharacterType (charTy, fileAttr, scope, loc,
303
+ /* hasDescriptor=*/ false );
278
304
} else if (auto boxTy = mlir::dyn_cast_or_null<fir::BoxType>(Ty)) {
279
305
auto elTy = boxTy.getElementType ();
280
306
if (auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(elTy))
0 commit comments