[llvm-dev] Should analyses be able to hold AssertingVH to IR? (related to PR28400)

Sean Silva via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 5 18:56:54 PDT 2016

While building test-suite with the new PM, I ran into problems with
AssertingVH being triggered which is obvious in retrospect:

Both cases I ran into revolve around LVI which holds AssertingVH.
Essentially, what happens is this:

1. LVI holds an AssertingVH pointing at a BasicBlock
2. Some other pass ends up deleting that BB (e.g. SimplifyCFG)

Notice that this ends up happening even though SimplifyCFG ultimately
invalidates LVI. But that only happens after the AssertingVH has been

We would avoid this issue in principle by just switching those AssertingVH
to observing pointers, but then we would have dangling pointers. I'm pretty
sure that any analysis that keeps pointers to IR is in fact ending up with
dangling pointers like this.

I've noticed that AssumptionCache using CallbackVH that allow it to update
its data structures correctly in this case.

Just using regular pointers will end up with dangling pointers in this
scenario. This isn't a problem in practice since the analysis will
hopefully be invalidated and stop holding the dangling pointers, but it
just seems weird. Thankfully, ASan can generally catch problems if we do
try to access through any of these dangling pointers.

Thoughts? For the moment I have put in a workaround (r274457) that makes
jump-threading invalidate LVI.

-- Sean Silva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160705/ceeb69a2/attachment.html>

More information about the llvm-dev mailing list