[IR] Make getFirstNonPHI return null if the BB is empty
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 7 Jul 2015 09:15:29 +0000 (09:15 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 7 Jul 2015 09:15:29 +0000 (09:15 +0000)
commit2822246ecee6237c706730ad519dc394918efe45
tree36a25b8484d0f47e28e6f06b74acc66c3a53346b
parent2b4a535b701656dfcc14ab362b72fa6664d4d2cd
[IR] Make getFirstNonPHI return null if the BB is empty

getFirstNonPHI's documentation states that it returns null if there is
no non-PHI instruction.  However, it instead returns a pointer to the
end iterator.  The implementation of getFirstNonPHI claims that
dereferencing the iterator will result in an assertion failure but this
doesn't occur.  Instead, machinery like getFirstInsertionPt will attempt
to isa<> this invalid memory which results in unpredictable behavior.
Instead, make getFirst* return null if no such instruction exists.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241570 91177308-0d34-0410-b5e6-96231b3b80d8
lib/IR/BasicBlock.cpp