[flang-commits] [flang] [flang][debug] Add fake use ops for dynamic array dimension variables (PR #200061)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Mon Jun 1 07:00:09 PDT 2026


================
@@ -53,4 +66,20 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<i128 = dense<128> : vector<2xi64
     fir.call @foo() : () -> ()
     return loc(#loc5)
   } loc(#loc1)
+
+  func.func @test_dynamic_array(%arg0: !fir.ref<!fir.array<?xi32>> {fir.bindc_name = "arr"} loc("debug-fake-use.f90":1:1), %arg1: !fir.ref<i32> {fir.bindc_name = "n"} loc("debug-fake-use.f90":1:1), %arg2: !fir.ref<i32> {fir.bindc_name = "lb"} loc("debug-fake-use.f90":1:1)) attributes {fir.internal_name = "_QPtest_dynamic_array"} {
+    %c0 = arith.constant 0 : index
+    %0 = fir.undefined !fir.dscope loc(#loc1)
+    %1 = fircg.ext_declare %arg1 dummy_scope %0 arg 2 {uniq_name = "_QFtest_dynamic_arrayEn"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32> loc(#loc3)
+    %2 = fircg.ext_declare %arg2 dummy_scope %0 arg 3 {uniq_name = "_QFtest_dynamic_arrayElb"} : (!fir.ref<i32>, !fir.dscope) -> !fir.ref<i32> loc(#loc4)
+    %3 = fir.load %1 : !fir.ref<i32>
+    %4 = fir.convert %3 : (i32) -> index
+    %5 = arith.cmpi sgt, %4, %c0 : index
+    %6 = arith.select %5, %4, %c0 : index
+    %7 = fir.load %2 : !fir.ref<i32>
+    %8 = fir.convert %7 : (i32) -> index
+    %9 = fircg.ext_declare %arg0(%6) origin %8 dummy_scope %0 arg 1 {uniq_name = "_QFtest_dynamic_arrayEarr"} : (!fir.ref<!fir.array<?xi32>>, index, index, !fir.dscope) -> !fir.ref<!fir.array<?xi32>> loc(#loc3)
+    fir.call @foo() : () -> ()
+    return loc(#loc5)
+  } loc(#loc1)
----------------
abidh wrote:

I think we can increase the test coverage a bit.

1. Not specific to your case but I think having a function with multiple returns would be a useful test.
2. Multi-dimensional array and/or having variable size with constant lower bound.

https://github.com/llvm/llvm-project/pull/200061


More information about the flang-commits mailing list