<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/120168>120168</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
opt dot-cfg pass print wrong dbg number or I misuse this pass?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tomgu1991
</td>
</tr>
</table>
<pre>
Hi, all, I use the following command to print cfg of llvm IR, but got the wrong dbg! number.
```cpp
//
// Created
//
void foo();
void bar();
void test1(int x) { foo(); }
void test2(int x) { bar(); }
```
```shell
clang -S -g -emit-llvm -Xclang -disable-O0-optnone -fno-discard-value-names test.cpp -o test.ll
opt -passes='dot-cfg' test.ll -S -o test_opt.ll
```
In the test_opt.ll(the same as test.ll) test1 is correct, as follows
<img width="1131" alt="Image" src="https://github.com/user-attachments/assets/03a5745f-5b99-403c-b110-349f25fd21df" />
But, in the test_opt.ll, test2 is the following: !dbg! is from 21 to 23
```
; Function Attrs: mustprogress noinline uwtable
define dso_local void @_Z5test2i(i32 noundef %x) #0 !dbg !19 {
entry:
%x.addr = alloca i32, align 4
store i32 %x, ptr %x.addr, align 4
call void @llvm.dbg.declare(metadata ptr %x.addr, metadata !20, metadata !DIExpression()), !dbg !21
call void @_Z3barv(), !dbg !22
ret void, !dbg !23
}
!16 = !DILocation(line: 8, column: 16, scope: !10)
!17 = !DILocation(line: 8, column: 21, scope: !10)
!18 = !DILocation(line: 8, column: 28, scope: !10)
!19 = distinct !DISubprogram(name: "test2", linkageName: "_Z5test2i", scope: !1, file: !1, line: 10, type: !11, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14)
!20 = !DILocalVariable(name: "x", arg: 1, scope: !19, file: !1, line: 10, type: !13)
!21 = !DILocation(line: 10, column: 16, scope: !19)
!22 = !DILocation(line: 10, column: 21, scope: !19)
!23 = !DILocation(line: 10, column: 28, scope: !19)
```
However, the dbg in dot is from 16 to 18,
<img width="1131" alt="Image" src="https://github.com/user-attachments/assets/c0064423-f2eb-4c3a-a2cd-c0228c36878f" />
So, is it a bug in opt dot-cfg pass or I misuse this?
Thanks!
zuxing
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8Vk2L4zwS_jXKpXCwSs6HDzmkkwkTGGaH7WVZ5tLIkuxox5aMJHf3vL_-RbLT6SRDQ19eMNguVT2qj6dK4t7rxii1IYsHstjP-BBO1m2C7ZqBliWdVVb-3nzVBHfA2za-jjB4BeGkoLZta1-0aUDYruNGQrDQO20CiLoBW0PbPndw_Hc0q4YAjQ3J8MVZ04CsGoIUzNBVys1Jvo3PMh8f0ffxFw_xOX_AzikelISrpXz7bLWE2lqCa4IlYQ9nWcXde9lZHJQPlOA6evpKsASyeriyB7La3-jjrf577LP-2fubYPxJtS3Jt6LlpoHsEbIGMtXpkKUEZf-bFqT2vGpV9q88s30w1ijIamOjXHAns2feDiozvFM--TQXfQ-ZHb_TDrYPkPXce-UJ2xNcSRsyUTcEV2ettP9o82T7ye7G86NJdXqvg-so8bxTwP3bjliOyQTtQVjnlAiJKn4ih494bKe7Bl60DKfkFFLKKEEE3oZRcOx4o6LEOzFKTiH0nrCpzI0Op6GaC9sRPAxeuYyHwMWpUyZ4gocYcPrIGV-sikWdLaqyzIqciayiNM9YUda4qCVSWcd9Iiz7MpUp3z4MyW39h7B3Y_VjgFecJ2wLBOlEYu2hdrYDpLEHkN2mlD3AYTAiaGtgG4KLoUE3-NA72zjlPRirTauNguElRBKQfCtVHQXS26fWCt5CIiMp8qefi-SUjpxkCMYORqoaCC5GeiLLJ-fiiybCknyrTHC_Y1LzLSTlOZfSAWH72NxWcNAMx1bXjYEi6flgnYoLE_wO-uAu1rfqgrcXRyO957Jq5lKJljtFcN2pwCUP_B7lbYUgxfxWsj9-ee1jprQ1U9_FZ_cuTqT3Hjz9ZBV3z2eLK3VM6k6FpH2zyNKQGdsa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