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().
The problem can be shown by compiling the following example with clang --target=armv8a-none-none-eabi -O3:
void v0(); void v1(); void v2(); void v3(); void v4(); int a; void test(void) { switch (a) { default: v0(); break; case 1: v1(); break; case 2: v2(); break; case 3: v3(); break; case 4: v4(); break; } try { throw 0; } catch (int) { } }