removeFromParent()/eraseFromParent()

I want to remove instruction from LLVM IR .I used eraseFromParent() in new pass to remove instruction .But when I run this pass I am getting error as

llvm/include/llvm/Support/Casting.h:90: static bool llvm::isa_impl_cl<To, From*>::doit(const From*) [with To = llvm::BinaryOperator; From = llvm::Instruction]: Assertion `Val && “isa<> used on a null pointer”’ failed.

I used erasefromparent as below:
for (auto Inst = BB.begin(), IE = BB.end(); Inst != IE; ++Inst) {
Inst->eraseFromParent();
}

Thank You

I suspect the problem is that you are erasing your iterator, and then incrementing it.
I’d try to write this way:

for (Instruction &Inst : make_early_inc_range(BB))
  Inst.eraseFromParent();