[PATCH] D43219: [PartialInlining] Fix Crash from holding a reference to a destructed ORE
Sean Fertile via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 12 19:41:25 PST 2018
sfertile created this revision.
sfertile added reviewers: fhahn, davidxl, davide, eli.friedman, eastig.
Herald added a subscriber: eraman.
The Legacy Partial Inlining pass has an ownership issue related to the OptimizationRemarkEmitter objects it creates. The call back used to create an ORE caches the allocated object in a unique_ptr in the runOnModule function, and returns a reference to that object. In the case we find a multi-region outline candidate that fails to get inlined into any of its users we end up with a dangling reference. This occurs because we get a reference to an ORE in unswitchFunction which gets destructed when tryPartialInline calls the callback to create other ORE objects. After we fail to inline in the multi-region case, we continue on with the single-region case which tries to emit a remark with the now deleted emitter.
This patch moves the ORE creation into a scope which avoids the problem, but there is still a potential pitfall here. Its not apparent that the ORE is invalidated by the call to tryPartialInline. I have toyed with a follow on patch that changes the GetORE callbacks to return a unique_ptr to an ORE instead, but thought I would post this change first to start the discussion of what the proper fix should look like.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 29664 bytes
Desc: not available
More information about the llvm-commits