Skip to content

Commit 1e4820c

Browse files
committed
Avoid changing declOp and add tests.
1 parent 1583977 commit 1e4820c

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -315,25 +315,31 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertRecordType(
315315
std::optional<llvm::ArrayRef<int64_t>> lowerBounds =
316316
fir::getComponentLowerBoundsIfNonDefault(Ty, fieldName, module,
317317
symbolTable);
318+
auto seqTy = mlir::dyn_cast_or_null<fir::SequenceType>(fieldTy);
318319

319320
// For members of the derived types, the information about the shift in
320321
// 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.
322+
// TypeInfoOp (using getComponentLowerBoundsIfNonDefault).
324323
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);
324+
if (lowerBounds && seqTy &&
325+
lowerBounds->size() == seqTy.getShape().size()) {
326+
llvm::SmallVector<mlir::LLVM::DINodeAttr> elements;
327+
for (auto [bound, dim] :
328+
llvm::zip_equal(*lowerBounds, seqTy.getShape())) {
329+
auto countAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, dim));
330+
auto lowerAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, bound));
331+
auto subrangeTy = mlir::LLVM::DISubrangeAttr::get(
332+
context, countAttr, lowerAttr, /*upperBound=*/nullptr,
333+
/*stride=*/nullptr);
334+
elements.push_back(subrangeTy);
331335
}
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);
336+
elemTy = mlir::LLVM::DICompositeTypeAttr::get(
337+
context, llvm::dwarf::DW_TAG_array_type, /*name=*/nullptr,
338+
/*file=*/nullptr, /*line=*/0, /*scope=*/nullptr,
339+
convertType(seqTy.getEleTy(), fileAttr, scope, declOp),
340+
mlir::LLVM::DIFlags::Zero, /*sizeInBits=*/0, /*alignInBits=*/0,
341+
elements, /*dataLocation=*/nullptr, /*rank=*/nullptr,
342+
/*allocated=*/nullptr, /*associated=*/nullptr);
337343
} else
338344
elemTy = convertType(fieldTy, fileAttr, scope, /*declOp=*/nullptr);
339345
offset = llvm::alignTo(offset, byteAlign);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: fir-opt --add-debug-info --mlir-print-debuginfo %s | FileCheck %s
2+
3+
module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
4+
fir.global @_QMmEvar : !fir.type<_QMmTt1{elm:!fir.array<5xi32>,elm2:!fir.array<5x8xi32>}> {} loc(#loc1)
5+
fir.type_info @_QMmTt1 noinit nodestroy nofinal : !fir.type<_QMmTt1{elm:!fir.array<5xi32>,elm2:!fir.array<5x8xi32>}> component_info {
6+
fir.dt_component "elm" lbs [2]
7+
fir.dt_component "elm2" lbs [1, 3]
8+
} loc(#loc1)
9+
}
10+
#loc1 = loc("derived.f90":24:1)
11+
12+
13+
// CHECK-DAG: #[[TY1:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type, {{.*}} = #{{.*}}, elements = #llvm.di_subrange<count = 5 : i64, lowerBound = 2 : i64>>
14+
// CHECK-DAG: #[[TY2:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type, baseType = #{{.*}}, elements = #llvm.di_subrange<count = 5 : i64, lowerBound = 1 : i64>, #llvm.di_subrange<count = 8 : i64, lowerBound = 3 : i64>>
15+
// CHECK-DAG: #llvm.di_derived_type<tag = DW_TAG_member, name = "elm", baseType = #[[TY1]], sizeInBits = {{.*}}, alignInBits = {{.*}}>
16+
// CHECK-DAG: #llvm.di_derived_type<tag = DW_TAG_member, name = "elm2", baseType = #[[TY2]], sizeInBits = {{.*}}, alignInBits = {{.*}}>

0 commit comments

Comments
 (0)