This is an archive of the discontinued LLVM Phabricator instance.

[NFC] `goto fail` has failed us in the past...
ClosedPublic

Authored by beanz on Sep 15 2021, 6:43 PM.

Details

Summary

This patch replaces reliance on goto failure pattern with
llvm::scope_exit.

Diff Detail

Event Timeline

beanz requested review of this revision.Sep 15 2021, 6:43 PM
beanz created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2021, 6:43 PM
bkramer accepted this revision.Sep 21 2021, 3:21 AM

Looks good, thanks

This revision is now accepted and ready to land.Sep 21 2021, 3:21 AM
This revision was automatically updated to reflect the committed changes.

(A possibly more robust option - so that this doesn't regress if someone adds a new "return true" codepath & forgets to release the cleanup (it looks like a pretty long function with several exits, etc) - would be to move the code into an "impl" function and have the original function call it, check the result, and do the cleanup once?)

beanz added a subscriber: lhames.Sep 21 2021, 7:27 PM

I was talking with @lhames the other day about building a doWithCleanup abstraction that could take a labmda to perform and a lambda to cleanup on failure.

I was thinking I may take a stab at that this week.

I was talking with @lhames the other day about building a doWithCleanup abstraction that could take a labmda to perform and a lambda to cleanup on failure.

I was thinking I may take a stab at that this week.

Sure, would be nice - though I'd probably still argue that a 400 line lambda might be a bit unwieldy/unclear.