[LLVMdev] An unexpected behavior in RegionInfo's block_iterator

Tobias Grosser tobias at grosser.es
Fri May 2 14:42:11 PDT 2014


On 02/05/2014 23:26, Paul Vario wrote:
> Hi Fellows,
>
>     I notice an unexpected behavior in RegionInfo's block_iterator. Consider
> the following situation: a user creates her own region containing just a
> single basic block TheBB, then tries to have the block_iterator to print a
> DFS traversal of the region. The expected behavior should be that only the
> single basic block TheBB will be printed, but the real behavior is that
> block_iterator prints out all the basic blocks of the CFG starting from
> TheBB to the end.
>
>      It looks like the issue originates from setting the end iterator to
> (BasicBlock *) 0. I understand that the "region" detected by RegionInfo
> should never contain a single basic block or even a sequence of basic
> blocks. So maybe the above degenerated case is considered "will never
> happen"?
>
>      ... ...
>
>      BasicBlock *BB = Func.getARandomBasicBlock;
>
>      Region *R = new Region(BB, BB, RI, DT);
>      for (Region::block_iterator i = R->block_begin(),
>             e = R->block_end(); i != e; ++i) {
>           errs() << (*i)->getName() << "\n";
>        }


Hi Paul,

the exit basic block is the block after the region.

  BB0 < Entering Block
   |
   v
  BB1 < Entry and Exiting block
   |
   v
  BB2 < Exit block

So your code should probably be:

new Region(BB, *pred_begin(BB), RI, DT)

Let me know if it works for you. In case it does, we could add an assert 
to the constructor to catch these cases.

Cheers,
Tobias



More information about the llvm-dev mailing list