Skip to content

VoidCallRemoval: does not support InvokeInst #10

@stanislaw

Description

@stanislaw

This line:

if (instruction->getOpcode() != llvm::Instruction::Call &&

prevents the code that follows it to be executed for the InvokeInst instructions.

Changing it to

  if (instruction->getOpcode() != llvm::Instruction::Call &&
      instruction->getOpcode() != llvm::Instruction::Invoke) {
    return false;
  }

is a valid step but then LLVM compilation of the mutated module crashes on the well-known chunk of code:

      MCContext *Ctx;
      if (TM.addPassesToEmitMC(PM, Ctx, ObjStream))
        llvm_unreachable("Target does not support MC emission.");
      PM.run(M);
    }

According to the SO here,

I guess, it is because your BasicBlock ends with invoke instruction, so it serves as BB's terminator. So when you remove it, your BB lose its terminator and that's an error, because every BasicBlock should end with terminator instruction.

Which is the case for my test case.

Some additional code has to be written to handle this case of the InvokeInst.

void VoidCallRemoval::mutate(llvm::Instruction *instruction) {
  assert(instruction);
  assert(canMutate(instruction));

  instruction->print(llvm::outs(), true);

  instruction->eraseFromParent();

  /// Handle special case of InvokeInst
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions