Skip to content

Commit 1fc288b

Browse files
authored
[flang][debug] Handle lower bound in assumed size arrays. (llvm#108523)
Fixes llvm#108411
1 parent bc8a5d1 commit 1fc288b

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,23 +213,26 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType(
213213
convertType(seqTy.getEleTy(), fileAttr, scope, declOp);
214214

215215
unsigned index = 0;
216+
auto intTy = mlir::IntegerType::get(context, 64);
216217
for (fir::SequenceType::Extent dim : seqTy.getShape()) {
218+
int64_t shift = 1;
219+
if (declOp && declOp.getShift().size() > index) {
220+
if (std::optional<std::int64_t> optint =
221+
getIntIfConstant(declOp.getShift()[index]))
222+
shift = *optint;
223+
}
217224
if (dim == seqTy.getUnknownExtent()) {
225+
mlir::IntegerAttr lowerAttr = nullptr;
226+
if (declOp && declOp.getShift().size() > index)
227+
lowerAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, shift));
218228
// FIXME: This path is taken for assumed size arrays but also for arrays
219229
// with non constant extent. For the latter case, the DISubrangeAttr
220230
// should point to a variable which will have the extent at runtime.
221231
auto subrangeTy = mlir::LLVM::DISubrangeAttr::get(
222-
context, /*count=*/nullptr, /*lowerBound=*/nullptr,
223-
/*upperBound*/ nullptr, /*stride*/ nullptr);
232+
context, /*count=*/nullptr, lowerAttr, /*upperBound*/ nullptr,
233+
/*stride*/ nullptr);
224234
elements.push_back(subrangeTy);
225235
} else {
226-
auto intTy = mlir::IntegerType::get(context, 64);
227-
int64_t shift = 1;
228-
if (declOp && declOp.getShift().size() > index) {
229-
if (std::optional<std::int64_t> optint =
230-
getIntIfConstant(declOp.getShift()[index]))
231-
shift = *optint;
232-
}
233236
auto countAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, dim));
234237
auto lowerAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, shift));
235238
auto subrangeTy = mlir::LLVM::DISubrangeAttr::get(

flang/test/Transforms/debug-assumed-size-array.fir

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
44
func.func @_QMhelperPfn(%arg0: !fir.ref<!fir.array<5x?xi32>> {fir.bindc_name = "a1"}, %arg1: !fir.ref<!fir.array<?xi32>> {fir.bindc_name = "a2"}, %arg2: !fir.ref<!fir.array<2x?xi32>> {fir.bindc_name = "a3"}) {
55
%c5 = arith.constant 5 : index
66
%c1 = arith.constant 1 : index
7+
%c2 = arith.constant 2 : index
78
%c-1 = arith.constant -1 : index
89
%0 = fir.undefined !fir.dscope
910
%1 = fircg.ext_declare %arg0(%c5, %c-1) dummy_scope %0 {uniq_name = "_QMhelperFfnEa1"} : (!fir.ref<!fir.array<5x?xi32>>, index, index, !fir.dscope) -> !fir.ref<!fir.array<5x?xi32>> loc(#loc1)
10-
%2 = fircg.ext_declare %arg1(%c-1) dummy_scope %0 {uniq_name = "_QMhelperFfnEa2"} : (!fir.ref<!fir.array<?xi32>>, index, !fir.dscope) -> !fir.ref<!fir.array<?xi32>> loc(#loc2)
11+
%2 = fircg.ext_declare %arg1(%c-1) origin %c2 dummy_scope %0 {uniq_name = "_QMhelperFfnEa2"} : (!fir.ref<!fir.array<?xi32>>, index, index, !fir.dscope) -> !fir.ref<!fir.array<?xi32>> loc(#loc2)
1112
return
1213
} loc(#loc3)
1314
}
@@ -16,6 +17,6 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} {
1617
#loc2 = loc("test.f90":4:1)
1718

1819
// CHECK-DAG: #[[TY1:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<count = 5 : i64, lowerBound = 1 : i64>, #llvm.di_subrange<>>
19-
// CHECK-DAG: #[[TY2:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<>>
20+
// CHECK-DAG: #[[TY2:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<lowerBound = 2 : i64>>
2021
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "a1"{{.*}}type = #[[TY1]]>
2122
// CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "a2"{{.*}}type = #[[TY2]]>

0 commit comments

Comments
 (0)