[PATCH] D47233: [CodeGen] Emit MSVC RTTI for Obj-C EH types

Shoaib Meenai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 11 16:05:19 PDT 2018


smeenai added a comment.

Wrapping an Objective-C exception inside a C++ exception means dynamically constructing a C++ exception object and traversing the class hierarchy of the thrown Obj-C object to populate the catchable types array of the C++ exception. Microsoft's C++ runtime will perform the appropriate catch type comparisons, and this patch makes the compiler emit the right typeinfos into the exception handling tables for all of that to work. https://github.com/Microsoft/libobjc2/blob/f2e4c5ac4b3ac17f413a38bbc7ee1242f9efd0f7/msvc/eh_winobjc.cc#L116 is how WinObjC does this wrapping, for example.

Essentially, with this patch, `@catch (I *)` in Obj-C ends up generating the same exception handling table as `catch (struct I *)` in C++ would. If you're throwing an `I *` (or any derived class), the runtime will generate an exception object which is catchable by this handler (the catchable types array for that exception object will contain the appropriate typeinfo). Successive catch clauses don't need any special handling; they work the same way as they would in C++. The runtime is generating that exception object based on a dynamic traversal of the class hierarchy, so I think Obj-C's dynamic semantics should be respected.


Repository:
  rC Clang

https://reviews.llvm.org/D47233





More information about the cfe-commits mailing list