This is an archive of the discontinued LLVM Phabricator instance.

Fix splitBasicBlock API
AbandonedPublic

Authored by sabuasal on Oct 18 2016, 7:22 PM.

Details

Summary

Avoid dereferencing a sentinel node in splitBasicBlock while updating Phi nodes in successor basic blocks. This is needed after r279314 added an assertion to guard against that. The for loop updated in this patch can possibly deference a pointer which could be pointing to a Sentinel and hence hitting the assertion.

Diff Detail

Event Timeline

sabuasal updated this revision to Diff 75102.Oct 18 2016, 7:22 PM
sabuasal retitled this revision from to Fix splitBasicBlock API.
sabuasal updated this object.

In the future, please make sure you add llvm-commits as a subscriber when you create the revision, not afterwards. If you do it the wrong way around, the patch itself is never sent to llvm-commits.

mehdi_amini edited edge metadata.Oct 21 2016, 4:03 PM

This could happen only if the block is empty, right?

MatzeB added a subscriber: MatzeB.Oct 21 2016, 4:14 PM

LLVM language ref says: "Each basic block may optionally start with a label (giving the basic block a symbol table entry), contains a list of instructions, and ends with a terminator instruction (such as a branch or function return)." So I would expect a terminator after the last PHI instruction or is this used in some intermediate steps where that rule is temporarily broken?

What if it is a basic block that only has a terminator instruction without any Phi nodes? is that an allowed basic block in LLVM?

What if it is a basic block that only has a terminator instruction without any Phi nodes? is that an allowed basic block in LLVM?

That is fine, but then this loop should have no problem because that terminator will return nullptr for dyn_cast<PHINode>.

sabuasal edited edge metadata.Oct 25 2016, 7:48 PM
sabuasal added a subscriber: zinob.
sabuasal abandoned this revision.Jun 28 2017, 11:21 AM