-struct GlobalsModRef::DeletionCallbackHandle final : CallbackVH {
- GlobalsModRef &GMR;
- std::list<DeletionCallbackHandle>::iterator I;
-
- DeletionCallbackHandle(GlobalsModRef &GMR, Value *V)
- : CallbackVH(V), GMR(GMR) {}
-
- void deleted() override {
- Value *V = getValPtr();
- if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
- if (GMR.NonAddressTakenGlobals.erase(GV)) {
- // This global might be an indirect global. If so, remove it and remove
- // any AllocRelatedValues for it.
- if (GMR.IndirectGlobals.erase(GV)) {
- // Remove any entries in AllocsForIndirectGlobals for this global.
- for (std::map<const Value *, const GlobalValue *>::iterator
- I = GMR.AllocsForIndirectGlobals.begin(),
- E = GMR.AllocsForIndirectGlobals.end();
- I != E;) {
- if (I->second == GV) {
- GMR.AllocsForIndirectGlobals.erase(I++);
- } else {
- ++I;
- }
- }
- }
- }
- }
-
- // If this is an allocation related to an indirect global, remove it.
- GMR.AllocsForIndirectGlobals.erase(V);
-
- // And clear out the handle.
- setValPtr(nullptr);
- GMR.Handles.erase(I);
- // This object is now destroyed!
- }
-};
-