This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by petpav01 on Nov 16 2015, 12:37 AM.

Details

Summary

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) {
  }
}

Diff Detail

Event Timeline

petpav01 updated this revision to Diff 40252.Nov 16 2015, 12:37 AM
petpav01 retitled this revision from to [ARM] Prevent use of a value pointed by end() iterator when placing a jump table.
petpav01 updated this object.
petpav01 added a subscriber: llvm-commits.
This revision was automatically updated to reflect the committed changes.