This is an archive of the discontinued LLVM Phabricator instance.

[CGObjC] Open cleanup scope before SaveAndRestore CurrentFuncletPad and push CatchRetScope early
ClosedPublic

Authored by sgraenitz on Nov 14 2022, 5:55 AM.

Details

Summary

Pushing the CatchRetScope early causes cleanups for catch parameters to be emitted in the basic block of the catch handler instead of the catchret.dest block. This is important because the latter is not part of the catchpad and this caused code truncations due to ARC PreISel intrinsics in WinEHPrepare.

Diff Detail

Event Timeline

sgraenitz created this revision.Nov 14 2022, 5:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2022, 5:55 AM
sgraenitz requested review of this revision.Nov 14 2022, 5:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2022, 5:55 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

The approach follows the C++ try/catch implementation in clang/lib/CodeGen/CGException.cpp. I think this is the correct solution for what I attempted to fix with D134866 in the backend before.

rnk added a comment.Nov 16 2022, 3:55 PM

Thanks, I can see the bug here:
https://gcc.godbolt.org/z/1xjMYarT9
You can see how storeStrong cleanup uses the catchpad funclet when it should not.

clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
36

Don't we need an exceptional cleanup here to release the exception if do_something or may_throw throw?

sgraenitz updated this revision to Diff 476150.Nov 17 2022, 8:56 AM
sgraenitz marked an inline comment as done.

Run test with -fobjc-arc-exceptions and check cleanup pads as well

sgraenitz added inline comments.Nov 17 2022, 8:59 AM
clang/test/CodeGenObjCXX/arc-exceptions-seh.mm
36

Thanks, that's a very good point! -fobjc-arc-exceptions tells clang to generate invokes here instead of calls and then we can check funclet tokens in cleanup pads too.

rnk accepted this revision.Nov 17 2022, 1:05 PM

lgtm, thanks!

This revision is now accepted and ready to land.Nov 17 2022, 1:05 PM
This revision was landed with ongoing or failed builds.Nov 22 2022, 3:03 AM
This revision was automatically updated to reflect the committed changes.