We used the predecessors()
to get the predecessors of a basic block based on LLVM's IR. The code is like:
for (llvm::BasicBlock* pred_bb : predecessors(cur_bb)) {
printf("prev_bb=%p\n", pred_bb); /* for debug */
}
However, we found that the predecessors()
could return duplicate basic block pointers. The output of above code could be:
prev_bb=0x56407eaee190
prev_bb=0x56407eaee190
prev_bb=0x56407eaee190
prev_bb=0x56407eaee190
prev_bb=0x56407eaee190
We further found these duplicate predecessors mostly apear in switch instructions. An github issue has mentioned this situtaion (https://github.com/NETMF/llilum/issues/76).
To resolve this situation, we have to check the result of predecessors()
before usage.