int CurrentBaseState;
int NextState;
- SmallVector<ActionHandler *, 4> HandlerStack;
+ SmallVector<std::unique_ptr<ActionHandler>, 4> HandlerStack;
SmallPtrSet<const Function *, 4> VisitedHandlers;
int currentEHNumber() const {
void createUnwindMapEntry(int ToState, ActionHandler *AH);
void createTryBlockMapEntry(int TryLow, int TryHigh,
ArrayRef<CatchHandler *> Handlers);
- void processCallSite(ArrayRef<ActionHandler *> Actions, ImmutableCallSite CS);
+ void processCallSite(MutableArrayRef<std::unique_ptr<ActionHandler>> Actions,
+ ImmutableCallSite CS);
void calculateStateNumbers(const Function &F);
};
}
// Parse the llvm.eh.actions call we found.
MachineBasicBlock *LPadMBB = MBBMap[LP->getParent()];
- SmallVector<ActionHandler *, 4> Actions;
+ SmallVector<std::unique_ptr<ActionHandler>, 4> Actions;
parseEHActions(ActionsCall, Actions);
// Iterate EH actions from most to least precedence, which means
// iterating in reverse.
for (auto I = Actions.rbegin(), E = Actions.rend(); I != E; ++I) {
- ActionHandler *Action = *I;
+ ActionHandler *Action = I->get();
if (auto *CH = dyn_cast<CatchHandler>(Action)) {
const auto *Filter =
dyn_cast<Function>(CH->getSelector()->stripPointerCasts());
MMI.addSEHCleanupHandler(LPadMBB, Fini);
}
}
- DeleteContainerPointers(Actions);
}
}
#endif
}
-void WinEHNumbering::processCallSite(ArrayRef<ActionHandler *> Actions,
- ImmutableCallSite CS) {
+void WinEHNumbering::processCallSite(
+ MutableArrayRef<std::unique_ptr<ActionHandler>> Actions,
+ ImmutableCallSite CS) {
DEBUG(dbgs() << "processCallSite (EH state = " << currentEHNumber()
<< ") for: ");
print_name(CS ? CS.getCalledValue() : nullptr);
if (HandlerStack[FirstMismatch]->getHandlerBlockOrFunc() !=
Actions[FirstMismatch]->getHandlerBlockOrFunc())
break;
- // Delete any actions that are already represented on the handler stack.
- delete Actions[FirstMismatch];
}
// Don't recurse while we are looping over the handler stack. Instead, defer
// the numbering of the catch handlers until we are done popping.
SmallVector<CatchHandler *, 4> PoppedCatches;
for (int I = HandlerStack.size() - 1; I >= FirstMismatch; --I) {
- if (auto *CH = dyn_cast<CatchHandler>(HandlerStack.back())) {
- PoppedCatches.push_back(CH);
- } else {
- // Delete cleanup handlers
- delete HandlerStack.back();
- }
- HandlerStack.pop_back();
+ std::unique_ptr<ActionHandler> Handler = HandlerStack.pop_back_val();
+ if (isa<CatchHandler>(Handler.get()))
+ PoppedCatches.push_back(cast<CatchHandler>(Handler.release()));
}
int TryHigh = NextState - 1;
auto Handlers =
makeArrayRef(&PoppedCatches[LastTryLowIdx], I - LastTryLowIdx + 1);
DEBUG(dbgs() << "createTryBlockMapEntry(" << TryLow << ", " << TryHigh);
- for (int J = 0; J < Handlers.size(); ++J) {
+ for (size_t J = 0; J < Handlers.size(); ++J) {
DEBUG(dbgs() << ", ");
print_name(Handlers[J]->getHandlerBlockOrFunc());
}
// The handler functions may have pushed actions onto the handler stack
// that we expected to push here. Compare the handler stack to our
// actions again to check for that possibility.
- if (HandlerStack.size() > FirstMismatch) {
+ if (HandlerStack.size() > (size_t)FirstMismatch) {
for (int E = std::min(HandlerStack.size(), Actions.size());
FirstMismatch < E; ++FirstMismatch) {
if (HandlerStack[FirstMismatch]->getHandlerBlockOrFunc() !=
Actions[FirstMismatch]->getHandlerBlockOrFunc())
break;
- delete Actions[FirstMismatch];
}
}
bool LastActionWasCatch = false;
for (size_t I = FirstMismatch; I != Actions.size(); ++I) {
// We can reuse eh states when pushing two catches for the same invoke.
- bool CurrActionIsCatch = isa<CatchHandler>(Actions[I]);
+ bool CurrActionIsCatch = isa<CatchHandler>(Actions[I].get());
// FIXME: Reenable this optimization!
if (CurrActionIsCatch && LastActionWasCatch && false) {
DEBUG(dbgs() << "setEHState for handler to " << currentEHNumber()
DEBUG(dbgs() << "createUnwindMapEntry(" << currentEHNumber() << ", ");
print_name(Actions[I]->getHandlerBlockOrFunc());
DEBUG(dbgs() << ")\n");
- createUnwindMapEntry(currentEHNumber(), Actions[I]);
+ createUnwindMapEntry(currentEHNumber(), Actions[I].get());
DEBUG(dbgs() << "setEHState for handler to " << NextState << "\n");
Actions[I]->setEHState(NextState);
NextState++;
}
- HandlerStack.push_back(Actions[I]);
+ HandlerStack.push_back(std::move(Actions[I]));
LastActionWasCatch = CurrActionIsCatch;
}
}
DEBUG(dbgs() << "Calculating state numbers for: " << F.getName() << '\n');
- SmallVector<ActionHandler *, 4> ActionList;
+ SmallVector<std::unique_ptr<ActionHandler>, 4> ActionList;
for (const BasicBlock &BB : F) {
for (const Instruction &I : BB) {
const auto *CI = dyn_cast<CallInst>(&I);
ByValArgFrameIndexMap.clear();
RegFixups.clear();
StatepointStackSlots.clear();
+ StatepointRelocatedValues.clear();
PreferredExtendType.clear();
}