[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
Wed Jun 17 11:02:15 PDT 2026
================
@@ -0,0 +1,165 @@
+// RUN: fir-opt --add-debug-info="emit-fake-use-for-debug-vars=true" %s | FileCheck %s --check-prefix=FAKE-USE
+// RUN: fir-opt --add-debug-info="emit-fake-use-for-debug-vars=false" %s | FileCheck %s --check-prefix=NO-FAKE-USE
+
+// Test that fir.fake_use ops are inserted for count and lower bound variables
+// in each dimension of a multi-dimensional dynamic array.
+
+// FAKE-USE-LABEL: func.func @test_2d_dynamic_array
+// FAKE-USE: fircg.ext_declare %arg0(%[[COUNT1:.*]], %[[COUNT2:.*]]) origin %[[LB1:.*]], %[[LB2:.*]] dummy_scope
+// FAKE-USE: fir.call @foo() : () -> ()
+// FAKE-USE: fir.fake_use %arg0
+// FAKE-USE: fir.fake_use %[[COUNT1]]
+// FAKE-USE: fir.fake_use %[[COUNT2]]
+// FAKE-USE: fir.fake_use %[[LB1]]
+// FAKE-USE: fir.fake_use %[[LB2]]
+// FAKE-USE: return
+
+// NO-FAKE-USE-LABEL: func.func @test_2d_dynamic_array
+// NO-FAKE-USE: fircg.ext_declare %arg0(%{{.*}}, %{{.*}}) origin %{{.*}}, %{{.*}} dummy_scope
+// NO-FAKE-USE: fir.call @foo() : () -> ()
+// NO-FAKE-USE-NOT: fir.fake_use
+// NO-FAKE-USE: return
+
+// FAKE-USE-LABEL: func.func @test_3d_dynamic_array
+// FAKE-USE: fircg.ext_declare %arg0(%[[C1:.*]], %[[C2:.*]], %[[C3:.*]]) origin %[[L1:.*]], %[[L2:.*]], %[[L3:.*]] dummy_scope
+// FAKE-USE: fir.call @foo() : () -> ()
+// FAKE-USE: fir.fake_use %arg0
+// FAKE-USE: fir.fake_use %[[C1]]
+// FAKE-USE: fir.fake_use %[[C2]]
+// FAKE-USE: fir.fake_use %[[C3]]
+// FAKE-USE: fir.fake_use %[[L1]]
+// FAKE-USE: fir.fake_use %[[L2]]
+// FAKE-USE: fir.fake_use %[[L3]]
+// FAKE-USE: return
+
+// NO-FAKE-USE-LABEL: func.func @test_3d_dynamic_array
+// NO-FAKE-USE: fircg.ext_declare %arg0(%{{.*}}, %{{.*}}, %{{.*}}) origin %{{.*}}, %{{.*}}, %{{.*}} dummy_scope
+// NO-FAKE-USE: fir.call @foo() : () -> ()
+// NO-FAKE-USE-NOT: fir.fake_use
+// NO-FAKE-USE: return
+
+// FAKE-USE-LABEL: func.func @test_2d_dynamic_array_multi_ret
+// FAKE-USE: fircg.ext_declare %arg0(%[[MR_COUNT1:.*]], %[[MR_COUNT2:.*]]) origin %[[MR_LB1:.*]], %[[MR_LB2:.*]] dummy_scope
+// FAKE-USE: cf.cond_br %{{.*}}, ^bb1, ^bb2
+// FAKE-USE: ^bb1:
+// FAKE-USE: fir.fake_use %arg0
+// FAKE-USE: fir.fake_use %[[MR_COUNT1]]
+// FAKE-USE: fir.fake_use %[[MR_COUNT2]]
+// FAKE-USE: fir.fake_use %[[MR_LB1]]
+// FAKE-USE: fir.fake_use %[[MR_LB2]]
+// FAKE-USE: return
+// FAKE-USE: ^bb2:
+// FAKE-USE: fir.fake_use %arg0
+// FAKE-USE: fir.fake_use %[[MR_COUNT1]]
+// FAKE-USE: fir.fake_use %[[MR_COUNT2]]
+// FAKE-USE: fir.fake_use %[[MR_LB1]]
+// FAKE-USE: fir.fake_use %[[MR_LB2]]
+// FAKE-USE: return
+
+// NO-FAKE-USE-LABEL: func.func @test_2d_dynamic_array_multi_ret
+// NO-FAKE-USE: fircg.ext_declare %arg0(%{{.*}}, %{{.*}}) origin %{{.*}}, %{{.*}} dummy_scope
+// NO-FAKE-USE: cf.cond_br %{{.*}}, ^bb1, ^bb2
+// NO-FAKE-USE: ^bb1:
+// NO-FAKE-USE-NOT: fir.fake_use
+// NO-FAKE-USE: return
+// NO-FAKE-USE: ^bb2:
+// NO-FAKE-USE-NOT: fir.fake_use
+// NO-FAKE-USE: return
+
+#loc1 = loc("debug-fake-use-multiple-dimensions.f90":1:1)
+#loc3 = loc("debug-fake-use-multiple-dimensions.f90":3:14)
+#loc4 = loc("debug-fake-use-multiple-dimensions.f90":4:14)
+#loc5 = loc("debug-fake-use-multiple-dimensions.f90":5:1)
+#loc6 = loc("debug-fake-use-multiple-dimensions.f90":6:1)
+#loc = loc("debug-fake-use-multiple-dimensions.f90":0:0)
+
+module attributes {dlti.dl_spec = #dlti.dl_spec<i128 = dense<128> : vector<2xi64>, f80 = dense<128> : vector<2xi64>, i1 = dense<8> : vector<2xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i64 = dense<64> : vector<2xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i32 = dense<32> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, !llvm.ptr<270> = dense<32> : vector<4xi64>, i8 = dense<8> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, "dlti.stack_alignment" = 128 : i64, "dlti.mangling_mode" = "e", "dlti.endianness" = "little">, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", fir.target_cpu = "x86-64", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128", llvm.ident = "flang", llvm.target_triple = "x86_64-unknown-linux-gnu"} {
----------------
abidh wrote:
Most of the time, we don't need all the attributes on the module.
https://github.com/llvm/llvm-project/pull/200061
More information about the flang-commits
mailing list