This is an archive of the discontinued LLVM Phabricator instance.

MS ABI: Implement support for throwing a C++ exception
ClosedPublic

Authored by majnemer on Mar 4 2015, 3:18 PM.

Details

Summary

Throwing a C++ exception, under the MS ABI, is implemented using three
components:

  • ThrowInfo structure which contains information like CV qualifiers, what destructor to call and a pointer to the CatchableTypeArray.
  • In a significant departure from the Itanium ABI, copying by-value occurs in the runtime and not at the catch site. This means we need to enumerate all possible types that this exception could be caught as and encode the necessary information to convert from the exception object's type to the catch handler's type. This includes complicated derived to base conversions and the execution of copy-constructors.

N.B. This implementation doesn't support the execution of a
copy-constructor from within the runtime for now. Adding support for
that functionality is quite difficult due to things like default
argument expressions which may evaluate arbitrary code hiding in the
copy-constructor's parameters.

Diff Detail

Repository
rL LLVM

Event Timeline

majnemer updated this revision to Diff 21237.Mar 4 2015, 3:18 PM
majnemer updated this revision to Diff 21238.
majnemer retitled this revision from to MS ABI: Implement support for throwing a C++ exception.
majnemer updated this object.
majnemer added a reviewer: rnk.
majnemer added a subscriber: Unknown Object (MLST).
  • Add a test to exercise throw
rnk accepted this revision.Mar 4 2015, 4:16 PM
rnk edited edge metadata.

lgtm

lib/CodeGen/CGException.cpp
360–363 ↗(On Diff #21238)

Based on reading this comment, it seems like we don't need this on Windows. Move it to ItaniumCXXABI?

lib/CodeGen/MicrosoftCXXABI.cpp
591 ↗(On Diff #21238)

Hm, annoying creating such struct types is annoying. Oh well.

593–596 ↗(On Diff #21238)

Hoist this over building the name string.

622 ↗(On Diff #21238)

Memoize it?

3258–3259 ↗(On Diff #21238)

Can we assert that T is not a reference type here?

3287 ↗(On Diff #21238)

So presumably this data cannot be dllexported. It's address is insignificant, similar RTTI? Make it unnamed_addr?

3288 ↗(On Diff #21238)

Can you do StringRef(MangleName) instead of MangledName.c_str() and see if that works? It's supposed to take a Twine.

3314 ↗(On Diff #21238)

We don't usually declare local scalars as const.

3314 ↗(On Diff #21238)

Is it useful to assert that T isn't a reference type?

This revision is now accepted and ready to land.Mar 4 2015, 4:16 PM
This revision was automatically updated to reflect the committed changes.