15
15
#include " DebugTypeGenerator.h"
16
16
#include " flang/Optimizer/CodeGen/DescriptorModel.h"
17
17
#include " flang/Optimizer/Support/InternalNames.h"
18
+ #include " flang/Optimizer/Support/Utils.h"
18
19
#include " mlir/Pass/Pass.h"
19
20
#include " llvm/ADT/ScopeExit.h"
20
21
#include " llvm/BinaryFormat/Dwarf.h"
@@ -298,6 +299,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
298
299
fir::TypeInfoOp tiOp = symbolTable->lookup <fir::TypeInfoOp>(Ty.getName ());
299
300
unsigned line = (tiOp) ? getLineFromLoc (tiOp.getLoc ()) : 1 ;
300
301
302
+ mlir::OpBuilder builder (context);
303
+ mlir::IntegerType intTy = mlir::IntegerType::get (context, 64 );
301
304
std::uint64_t offset = 0 ;
302
305
for (auto [fieldName, fieldTy] : Ty.getTypeList ()) {
303
306
mlir::Type llvmTy;
@@ -307,11 +310,32 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
307
310
else
308
311
llvmTy = llvmTypeConverter.convertType (fieldTy);
309
312
310
- // FIXME: Handle non defaults array bound in derived types
311
313
uint64_t byteSize = dataLayout->getTypeSize (llvmTy);
312
314
unsigned short byteAlign = dataLayout->getTypeABIAlignment (llvmTy);
313
- mlir::LLVM::DITypeAttr elemTy =
314
- convertType (fieldTy, fileAttr, scope, /* declOp=*/ nullptr );
315
+ std::optional<llvm::ArrayRef<int64_t >> lowerBounds =
316
+ fir::getComponentLowerBoundsIfNonDefault (Ty, fieldName, module,
317
+ symbolTable);
318
+
319
+ // For members of the derived types, the information about the shift in
320
+ // lower bounds is not part of the declOp but has to be extracted from the
321
+ // TypeInfoOp (using getComponentLowerBoundsIfNonDefault). We then assign it
322
+ // temporarily to the declOp to propagate this information where it will be
323
+ // needed by the type conversion logic.
324
+ mlir::LLVM::DITypeAttr elemTy;
325
+ if (declOp && lowerBounds) {
326
+ llvm::SmallVector<mlir::Value> shiftOpers;
327
+ for (int64_t bound : *lowerBounds) {
328
+ auto constOp = builder.create <mlir::arith::ConstantOp>(
329
+ module.getLoc (), builder.getIntegerAttr (intTy, bound));
330
+ shiftOpers.push_back (constOp);
331
+ }
332
+ mlir::OperandRange originalShift = declOp.getShift ();
333
+ mlir::MutableOperandRange mutableOpRange = declOp.getShiftMutable ();
334
+ mutableOpRange.assign (shiftOpers);
335
+ elemTy = convertType (fieldTy, fileAttr, scope, declOp);
336
+ mutableOpRange.assign (originalShift);
337
+ } else
338
+ elemTy = convertType (fieldTy, fileAttr, scope, /* declOp=*/ nullptr );
315
339
offset = llvm::alignTo (offset, byteAlign);
316
340
mlir::LLVM::DIDerivedTypeAttr tyAttr = mlir::LLVM::DIDerivedTypeAttr::get (
317
341
context, llvm::dwarf::DW_TAG_member,
0 commit comments