<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75299>75299</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Error when using Instruction.getDebugLoc().getLine()
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
S-Hang23
</td>
</tr>
</table>
<pre>
I met an error when I am writing a llvm pass to analyze the live variables in a program. I want to push the liveness information accoding to the line number in the source code.
```
if (Instruction *I = dyn_cast<Instruction>(&*inst)) {
if(sourceLineNum != I->getDebugLoc().getLine()){
sourceLineNum = I->getDebugLoc().getLine();
BlockInfo.pushBitVector(BV);
}
```
I use clang -g to include debug info in my .ll file.
However I met such error:
```log
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: opt-14 -load ./build/libLiveVariableInBranchPass.so -live-var-in-branch test2.ll -enable-new-pm=0
1. Running pass 'Function Pass Manager' on module 'test2.ll'.
2. Running pass 'LiveVariableInBranch Pass' on function '@foo'
#0 0x00007f2ec50e9d01 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe3fd01)
#1 0x00007f2ec50e7a3e llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe3da3e)
#2 0x00007f2ec50ea236 (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe40236)
#3 0x00007f2ec3d91520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f2ec51ad0c3 llvm::DebugLoc::getLine() const (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xf030c3)
#5 0x00007f2ec1c4a8de (anonymous namespace)::LiveVariableInBranch::getLivenessInSingleBB(llvm::BasicBlock&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, int> > >) LiveVariableInBranchSkeleton.cpp:0:0
#6 0x00007f2ec1c4a4a6 (anonymous namespace)::LiveVariableInBranch::runOnFunction(llvm::Function&) LiveVariableInBranchSkeleton.cpp:0:0
#7 0x00007f2ec5224390 llvm::FPPassManager::runOnFunction(llvm::Function&) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xf7a390)
#8 0x00007f2ec522b983 llvm::FPPassManager::runOnModule(llvm::Module&) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xf81983)
#9 0x00007f2ec5224f36 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xf7af36)
#10 0x000000000043468b main (/usr/lib/llvm-14/bin/opt+0x43468b)
#11 0x00007f2ec3d78d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#12 0x00007f2ec3d78e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#13 0x000000000041a785 _start (/usr/lib/llvm-14/bin/opt+0x41a785)
Segmentation fault (core dumped)
```
I can't get why this occurs. When I deleted the code about push liveness info when line number changes, the pass worked normally.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEV19v6j4S_TTmZUTk2OFPHngobdFF6t2tfl3dfUQTxwRvHRvZTin76Vd2KCWou9uLVvtDVCW25_hkfGY8g96rxki5IJMlmTyMsAs76xYv4x9oGsZHla2PizW0MgAakM5ZB4edNLAGbOHgVFCmAQSt31rYo_cQLKBBffynhLCToNWbhDd0CistPSgDCHtnG4dtBms4oAnRZN_53Xm9kT6u3FrXYlDWAAph67hRsKdFRoLp2kq6iBiHvO2ckCBsLTMg9IHQOzKlp296VFsgbL42PrhOJFjC7tZA-APUR7MR6APh9xfzhD8SNidsStidMj4QVhJWApkte0BQW8Lm_cZPysi_dC0QlkfA9Z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