LLVM程序分析日记之 basic blocks could have duplicate predecessors

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.

posted @ 2020-12-06 10:22  bjchan9an  阅读(183)  评论(1)    收藏  举报