This is an archive of the discontinued LLVM Phabricator instance.

[RegionInfo] Don't return an invalid pointer when removing a subregion
AbandonedPublic

Authored by thegameg on Mar 9 2017, 6:39 PM.

Details

Summary

RegionBase<Tr>::removeSubRegion removes a subregion from its children, then returns a pointer to the removed subregion.

Starting from r206310 (Use unique_ptr to manage ownership of child Regions within llvm::Region), the children are stored using a unique_ptr<RegionT>, which obviously deletes the region when the child is erased from the container, and returns an invalid pointer.

I see three solutions here:

  1. Don't return the removed child.
  2. Move the unique_ptr out of the container and return it. This would mean that we need to update all the other functions that take raw pointers and store them in unique_ptr internally (addSubRegion?).
  3. Release the unique_ptr and "transfer" the ownership to the caller.

I chose the first one, since in my use-case I don't need the removed subregion anymore, since I'm using transferChildrenTo.

Diff Detail

Event Timeline

thegameg created this revision.Mar 9 2017, 6:39 PM
MatzeB accepted this revision.Mar 9 2017, 6:42 PM

Looks like nobody uses the return value anyway. LGTM.

This revision is now accepted and ready to land.Mar 9 2017, 6:42 PM
thegameg updated this revision to Diff 91252.Mar 9 2017, 6:49 PM

Fix typo in comment.

thegameg abandoned this revision.Nov 28 2017, 9:38 AM