[flang-commits] [flang] 1fc288b - [flang][debug] Handle lower bound in assumed size arrays. (#108523)

via flang-commits flang-commits at lists.llvm.org
Tue Sep 17 03:02:14 PDT 2024


Author: Abid Qadeer
Date: 2024-09-17T11:02:10+01:00
New Revision: 1fc288bf481726393c73133eef9aa73c0f78312e

URL: https://github.com/llvm/llvm-project/commit/1fc288bf481726393c73133eef9aa73c0f78312e
DIFF: https://github.com/llvm/llvm-project/commit/1fc288bf481726393c73133eef9aa73c0f78312e.diff

LOG: [flang][debug] Handle lower bound in assumed size arrays. (#108523)

Fixes #108411

Added: 
    

Modified: 
    flang/lib/Optimizer/Transforms/DebugTypeGenerator.cpp
    flang/test/Transforms/debug-assumed-size-array.fir

Removed: 
    


################################################################################
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<std::int64_t> 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<std::int64_t> 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.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"}) {
     %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<!fir.array<5x?xi32>>, index, index, !fir.dscope) -> !fir.ref<!fir.array<5x?xi32>> loc(#loc1)
-    %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)
+    %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)
     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<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<count = 5 : i64, lowerBound = 1 : i64>, #llvm.di_subrange<>>
-// CHECK-DAG: #[[TY2:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<>>
+// CHECK-DAG: #[[TY2:.*]] = #llvm.di_composite_type<tag = DW_TAG_array_type{{.*}}elements = #llvm.di_subrange<lowerBound = 2 : i64>>
 // CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "a1"{{.*}}type = #[[TY1]]>
 // CHECK-DAG: #llvm.di_local_variable<{{.*}}name = "a2"{{.*}}type = #[[TY2]]>


        


More information about the flang-commits mailing list