This patch fixes a memory leak if Function::dropAllReferences() is followed by setHungoffOperand (e.g. setPersonality)
If NumUserOperands changes from 3 to 0 before calling allocHungoffUselist() to allocate memory,
the memory leaks which are allocated when NumUserOperands is changed from 0 to 3.
e.g.
llvm::Function* func = ...; func->setPersonalityFn(foo); // (1). call allocHungoffUselist() to allocate memory for uses func->deleteBody(); // (2). call dropAllReferences(), and it changes NumUserOperands from 3 to 0 // (3). at this point, NumUserOperands is 0, the next line will allocate memory by allocHungoffUselist() func->setPersonalityFn(bar); // (4). call allocHungoffUselist(), so memory allocated in (1) leaks.
I think you should add a parameter bool ShouldDrop so that you can share logic between dropAllReferences() and deleteBody().