This is an archive of the discontinued LLVM Phabricator instance.

Fix DebugInfo replaceAllUsesWith.
ClosedPublic

Authored by friss on Sep 12 2014, 12:59 AM.

Details

Summary

replaceAllUsesWith had been modified to allow a DbgNode value to be
replaced by itself. In that case a new node is created by copying the
current DbgNode and the copy is used as replacement value.

When that copying happens, the value stored in this->DbgNode at the end
of RAUW would be a reference to the Node that has just been deleted.

This doesn't produce any bug right now, because the DI node on which we
call RAUW won't be used again.

Diff Detail

Repository
rL LLVM

Event Timeline

friss updated this revision to Diff 13617.Sep 12 2014, 12:59 AM
friss retitled this revision from to Fix DebugInfo replaceAllUsesWith..
friss added reviewers: dblaikie, echristo, aprantl.
friss updated this object.
friss added a subscriber: Unknown Object (MLST).
aprantl edited edge metadata.Sep 12 2014, 8:44 AM

Good catch! We should probably add to the doxygen comment that this DIType is guaranteed to be valid, after this operation, and that it will wrap a new MDNode or D's MDNode, respectively.

I did not get why rauw'ing a node with itself isn't a noop. Why is the copy necesary?

friss added a comment.Sep 12 2014, 8:59 AM

You'd have to ask David if he remembers the details. I dug the commit history of this stuff, and he is the one that introduced it.

The commits are about memory leaks, thus I believe it was related to getting read of node allocated with MDNode::getTemporary(). In the following commits of the forward decl work, I definitely use it this way. If I have a real definition to replace the temporary forward decl, then RAUW with that, otherwise, RAUW with itself and it turns the temporary node in a permanent one avoiding memory leaks.

dblaikie accepted this revision.Sep 12 2014, 9:24 AM
dblaikie edited edge metadata.

Thanks for the catch

This revision is now accepted and ready to land.Sep 12 2014, 9:24 AM
friss closed this revision.Sep 15 2014, 1:00 AM
friss updated this revision to Diff 13693.

Closed by commit rL217749 (authored by @friss).