1515#include " DebugTypeGenerator.h"
1616#include " flang/Optimizer/CodeGen/DescriptorModel.h"
1717#include " flang/Optimizer/Support/InternalNames.h"
18+ #include " flang/Optimizer/Support/Utils.h"
1819#include " mlir/Pass/Pass.h"
1920#include " llvm/ADT/ScopeExit.h"
2021#include " llvm/BinaryFormat/Dwarf.h"
@@ -298,6 +299,8 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
298299 fir::TypeInfoOp tiOp = symbolTable->lookup <fir::TypeInfoOp>(Ty.getName ());
299300 unsigned line = (tiOp) ? getLineFromLoc (tiOp.getLoc ()) : 1 ;
300301
302+ mlir::OpBuilder builder (context);
303+ mlir::IntegerType intTy = mlir::IntegerType::get (context, 64 );
301304 std::uint64_t offset = 0 ;
302305 for (auto [fieldName, fieldTy] : Ty.getTypeList ()) {
303306 mlir::Type llvmTy;
@@ -307,11 +310,32 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
307310 else
308311 llvmTy = llvmTypeConverter.convertType (fieldTy);
309312
310- // FIXME: Handle non defaults array bound in derived types
311313 uint64_t byteSize = dataLayout->getTypeSize (llvmTy);
312314 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 );
315339 offset = llvm::alignTo (offset, byteAlign);
316340 mlir::LLVM::DIDerivedTypeAttr tyAttr = mlir::LLVM::DIDerivedTypeAttr::get (
317341 context, llvm::dwarf::DW_TAG_member,
0 commit comments