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:
- Don't return the removed child.
- 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?).
- 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.