[ARM] Prevent use of a value pointed by end() iterator when placing a jump table
authorPetr Pavlu <petr.pavlu@arm.com>
Mon, 16 Nov 2015 16:41:13 +0000 (16:41 +0000)
committerPetr Pavlu <petr.pavlu@arm.com>
Mon, 16 Nov 2015 16:41:13 +0000 (16:41 +0000)
commit1890cef0c5eea500cd3a54022d95f82fee313daf
tree9479d8e8fca99a30394c79a4f6d4eda9efb1d8f4
parent20bb042d74a95970b4942f38cb2606a84fc279f7
[ARM] Prevent use of a value pointed by end() iterator when placing a jump table

Function ARMConstantIslands::doInitialJumpTablePlacement() iterates over all
basic blocks in a machine function. It calls `MI = MBB.getLastNonDebugInstr()`
to get the last instruction in each block and then uses MI->getOpcode() to
decide what to do. If getLastNonDebugInstr() returns MBB.end() (for example,
when the block does not contain any instructions) then calling getOpcode() on
this value is incorrect. Avoid this problem by checking the result of
getLastNonDebugInstr().

Differential Revision: http://reviews.llvm.org/D14694

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253222 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/ARM/ARMConstantIslandPass.cpp