[llvm] r253222 - [ARM] Prevent use of a value pointed by end() iterator when placing a jump table

Petr Pavlu via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 16 08:41:13 PST 2015


Author: petr.pavlu
Date: Mon Nov 16 10:41:13 2015
New Revision: 253222

URL: http://llvm.org/viewvc/llvm-project?rev=253222&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp

Modified: llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp?rev=253222&r1=253221&r2=253222&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMConstantIslandPass.cpp Mon Nov 16 10:41:13 2015
@@ -589,6 +589,8 @@ void ARMConstantIslands::doInitialJumpTa
   MachineBasicBlock *LastCorrectlyNumberedBB = nullptr;
   for (MachineBasicBlock &MBB : *MF) {
     auto MI = MBB.getLastNonDebugInstr();
+    if (MI == MBB.end())
+      continue;
 
     unsigned JTOpcode;
     switch (MI->getOpcode()) {




More information about the llvm-commits mailing list