[PATCH] D47564: [Parse] Use CapturedStmt for @finally on MSVC

Shoaib Meenai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 30 16:47:57 PDT 2018


smeenai created this revision.
smeenai added reviewers: rjmccall, rnk, rsmith.
Herald added a subscriber: cfe-commits.

The body of a @finally needs to be executed on both exceptional and
non-exceptional paths. On landingpad platforms, this is straightforward:
the @finally body is emitted as a normal (non-exceptional) cleanup, and
then a catch-all is emitted which branches to that cleanup (the cleanup
has code to conditionally re-throw based on a flag which is set by the
catch-all).

Unfortunately, we can't use the same approach for MSVC exceptions, where
the catch-all will be emitted as a catchpad. We can't just branch to the
cleanup from within the catchpad, since we can only exit it via a
catchret, at which point the exception is destroyed and we can't
rethrow. We could potentially emit the finally body inside the catchpad
and have the normal cleanup path somehow branch into it, but that would
require some new IR construct that could branch into a catchpad.

Instead, after discussing it with Reid Kleckner, we decided that
frontend outlining was the best approach, similar to how SEH __finally
works today. We decided to use CapturedStmt rather than CaptureFinder
(which is what __finally uses) since the latter doesn't handle a lot of
cases we care about, e.g. self accesses, property accesses, block
captures, etc. Extending CaptureFinder to handle those additional cases
proved unwieldy, whereas CapturedStmt already took care of all of those.
In theory __finally could also be moved over to CapturedStmt, which
would remove some existing limitations (e.g. the inability to capture
this), although CaptureFinder would still be needed for SEH filters.

The one case supported by @finally but not CapturedStmt (or
CaptureFinder for that matter) is arbitrary control flow out of the
@finally, e.g. having a return statement inside a @finally. We can add
that support as a follow-up, but in practice we've found it to be used
very rarely anyway.


Repository:
  rC Clang

https://reviews.llvm.org/D47564

Files:
  include/clang/AST/Stmt.h
  include/clang/Basic/CapturedStmt.h
  include/clang/Sema/ScopeInfo.h
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGObjCMac.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Parse/ParseObjc.cpp
  test/CodeGenObjC/dllstorage.m
  test/CodeGenObjC/exceptions-msvc.m
  test/SemaObjC/finally-msvc.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47564.149219.patch
Type: text/x-patch
Size: 12600 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180530/28044a83/attachment.bin>


More information about the cfe-commits mailing list