This is an archive of the discontinued LLVM Phabricator instance.

[ObjCARC] Prevent code motion into a catchswitch
ClosedPublic

Authored by smeenai on May 4 2018, 4:39 PM.

Details

Summary

A catchswitch must be the only non-phi instruction in its basic block;
attempting to move a retain or release into a catchswitch basic block
will result in invalid IR. Explicitly mark a CFG hazard in this case to
prevent the code motion.

Fixes PR37332.

Diff Detail

Repository
rL LLVM

Event Timeline

smeenai created this revision.May 4 2018, 4:39 PM

I'm going to have to leave this one to Akira or Michael, sorry.

No worries; thanks for all the other reviews, and for adding Michael as a reviewer to this one :)

ahatanak added inline comments.May 15 2018, 10:11 AM
lib/Transforms/ObjCARC/ObjCARCOpts.cpp
1577 ↗(On Diff #145323)

If you want to set CFGHazardAfflicted inside BottomUpPtrState::HandlePotentialUse, perhaps you can read NewRetainRRI's CFGHazardAfflicted bit and set CFGHazardAfflicted here, just as it's done in line 1649?

1699 ↗(On Diff #145323)

This is preventing releases from being inserted before a CatchSwitchInst. Is that correct? Do you have to prevent retains from being inserted before CatchSwitchInsts too somewhere, or we don't have to worry about it because it never happens?

rnk added inline comments.May 15 2018, 10:34 AM
lib/Transforms/ObjCARC/ObjCARCOpts.cpp
1699 ↗(On Diff #145323)

Yes, a catchswitch must be the first and last non-phi instruction in the BB. It's BB must be empty. It only exists to multiplex unwind edges from invokes.

smeenai added inline comments.May 15 2018, 2:07 PM
lib/Transforms/ObjCARC/ObjCARCOpts.cpp
1577 ↗(On Diff #145323)

Let me try that, thanks!

1699 ↗(On Diff #145323)

I haven't seen retains be inserted before a catchswitch. I think that's because only the bottom-up analysis does the special treatment of invoke instructions, where they're analyzed as part of the successor basic blocks instead.

smeenai updated this revision to Diff 146922.May 15 2018, 2:38 PM
smeenai edited the summary of this revision. (Show Details)

@ahatanak's suggestion

This revision is now accepted and ready to land.May 15 2018, 9:50 PM
This revision was automatically updated to reflect the committed changes.