From 1fc288bf481726393c73133eef9aa73c0f78312e Mon Sep 17 00:00:00 2001 From: Abid Qadeer Date: Tue, 17 Sep 2024 11:02:10 +0100 Subject: [PATCH] [flang][debug] Handle lower bound in assumed size arrays. (#108523) Fixes #108411 --- .../Transforms/DebugTypeGenerator.cpp | 21 +++++++++++-------- .../Transforms/debug-assumed-size-array.fir | 5 +++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp index 7c4382079fd6d4..82c6a6618e0ed8 100644 --- a/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp +++ b/flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp @@ -213,23 +213,26 @@ mlir::LLVM::DITypeAttr DebugTypeGenerator::convertSequenceType( convertType(seqTy.getEleTy(), fileAttr, scope, declOp); unsigned index = 0; + auto intTy = mlir::IntegerType::get(context, 64); for (fir::SequenceType::Extent dim : seqTy.getShape()) { + int64_t shift = 1; + if (declOp && declOp.getShift().size() > index) { + if (std::optional optint = + getIntIfConstant(declOp.getShift()[index])) + shift = *optint; + } if (dim == seqTy.getUnknownExtent()) { + mlir::IntegerAttr lowerAttr = nullptr; + if (declOp && declOp.getShift().size() > index) + lowerAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, shift)); // FIXME: This path is taken for assumed size arrays but also for arrays // with non constant extent. For the latter case, the DISubrangeAttr // should point to a variable which will have the extent at runtime. auto subrangeTy = mlir::LLVM::DISubrangeAttr::get( - context, /*count=*/nullptr, /*lowerBound=*/nullptr, - /*upperBound*/ nullptr, /*stride*/ nullptr); + context, /*count=*/nullptr, lowerAttr, /*upperBound*/ nullptr, + /*stride*/ nullptr); elements.push_back(subrangeTy); } else { - auto intTy = mlir::IntegerType::get(context, 64); - int64_t shift = 1; - if (declOp && declOp.getShift().size() > index) { - if (std::optional optint = - getIntIfConstant(declOp.getShift()[index])) - shift = *optint; - } auto countAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, dim)); auto lowerAttr = mlir::IntegerAttr::get(intTy, llvm::APInt(64, shift)); auto subrangeTy = mlir::LLVM::DISubrangeAttr::get( diff --git a/flang/test/Transforms/debug-assumed-size-array.fir b/flang/test/Transforms/debug-assumed-size-array.fir index d25224fb1b5ec3..9adf711a0a6f7b 100644 --- a/flang/test/Transforms/debug-assumed-size-array.fir +++ b/flang/test/Transforms/debug-assumed-size-array.fir @@ -4,10 +4,11 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} { func.func @_QMhelperPfn(%arg0: !fir.ref> {fir.bindc_name = "a1"}, %arg1: !fir.ref> {fir.bindc_name = "a2"}, %arg2: !fir.ref> {fir.bindc_name = "a3"}) { %c5 = arith.constant 5 : index %c1 = arith.constant 1 : index + %c2 = arith.constant 2 : index %c-1 = arith.constant -1 : index %0 = fir.undefined !fir.dscope %1 = fircg.ext_declare %arg0(%c5, %c-1) dummy_scope %0 {uniq_name = "_QMhelperFfnEa1"} : (!fir.ref>, index, index, !fir.dscope) -> !fir.ref> loc(#loc1) - %2 = fircg.ext_declare %arg1(%c-1) dummy_scope %0 {uniq_name = "_QMhelperFfnEa2"} : (!fir.ref>, index, !fir.dscope) -> !fir.ref> loc(#loc2) + %2 = fircg.ext_declare %arg1(%c-1) origin %c2 dummy_scope %0 {uniq_name = "_QMhelperFfnEa2"} : (!fir.ref>, index, index, !fir.dscope) -> !fir.ref> loc(#loc2) return } loc(#loc3) } @@ -16,6 +17,6 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<>} { #loc2 = loc("test.f90":4:1) // CHECK-DAG: #[[TY1:.*]] = #llvm.di_composite_type, #llvm.di_subrange<>> -// CHECK-DAG: #[[TY2:.*]] = #llvm.di_composite_type> +// CHECK-DAG: #[[TY2:.*]] = #llvm.di_composite_type> // CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "a1"{{.*}}type = #[[TY1]]> // CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "a2"{{.*}}type = #[[TY2]]>