Features Download

From: Kaylor, Andrew <andrew.kaylor <at> intel.com>
Subject: Windows EH support
Newsgroups: gmane.comp.compilers.llvm.devel
Date: Friday 19th December 2014 00:50:01 UTC (over 3 years ago)
Hi Reid,

I'm trying to get a "big picture" view of everything that needs to be done
for clang and llvm to support SEH and C++ exception handling for the "msvc"
environment.  I've put together a list, including work in progress, but I'm
guessing that I've missed some details.  Can you look this over and tell me
if it matches your idea of what needs to be done?

Structured Exception Handling
* Add support for __try and __except in clang.

It looks like this is mostly implemented by your changes in the D5607
review, but there hasn't been any activity on that review for quite a
while.  You're going to rewrite a lot of that to change the way filters are
implemented, right?

* Add support for __finally in clang

I haven't seen anything for this yet.  Based on various discussions, it
seems like you intend to mix C++ scope cleanup with SEH handlers in ways
that MSVC specifically punts.  Is that right?

* Add support for unwinding in frames with no exception handlers

I'm not clear as to what needs to be done for this.  I know clang is
intentionally generating errors when you compile code with an
MSVC-environment target.  I'm guessing that just removing this block will
be sufficient for clang to generate the IR we want.  Then it will be up to
the back end to produce the correct unwinding support, which I think it may
already be doing.

* Add support for frame allocation intrinsics.

You've started this in review D6493, which seems to be progressing.  I
don't know how much remains to be done there, but I trust that you have it
under control.

* Add support for outlining filter functions.

This is partially implemented in my D6556 review.  I think that will be
ready to check in once the expected for of the input IR settles.  I still
need to add support for removing outlined code.  It will also need to make
use of the frame allocation intrinsics to reference frame variables in the
outlined code.  You've mentioned that we should also do analysis to
minimize the amount of duplicated code.  I agree but I was hoping that
could wait until everything else is in place and working.

* Add support for outlining __try bodies.

I don't know what your plan is for identifying the beginning and end of
these regions, but I expect that we'll be able to leverage the outlining
code from the task above to do most of the work for this task.

* Add support to emit .xdata table for SEH for 64-bit targets.

This is implemented in your D6300 review, but that looks like it has
stalled a bit.  Is there anything holding this up other than lack of

* Add support to generate stack-based EH tables for 32-bit targets.

I haven't seen any work on this.  Am I correct in thinking that other than
the placement of the EH tables the 32-bit implementation will be able to
re-use all of the other SEH code (IR generation, outlining, etc.)?

* Add more tests.

C++ Exception Handling
* Add support for MSVC-specific try-except IR emission to clang.

This seems fairly straight-forward.  I saw some code in your D5607 review
to add a way to access the correct personality function.  Other than that,
it looks like this will just be a matter of removing the "ErrorUnspported"
blocks and adding MSVC-specific support to the parts of the code that are
currently generating libc++abi calls for throwing and catching exceptions. 
The general shape of the IR generated seems to be correct.

* Add support for outlining C++ catch handlers

This will be very similar to the filter outlining in the D6556 review.  I
think a bit of extra effort will be required to correctly identify and
group cleanup handlers and get them mixed with the exception handlers
correctly, but overall I feel like I have a handle on this.

* Add support to emit .xdata table for C++EH for 64-bit targets.

The analogous SEH code should provide a stable location for where these
changes need to be made.  From there it seems to be a matter of plumbing to
get the handler addresses and new code to emit the table in the correct
format for the MSVC C++ personality function.

* Add support to generate stack-based C++EH tables for 32-bit targets

* Add more tests


I think I've mentioned before that C++ exception handling is my main
interest here.  I've been planning to follow through on the remaining work
for the function outlining for both SEH and C++EH.  Beyond that, I guess we
need to talk about what work you've already got in flight.  Would you want
me to work on the other C++EH tasks while you finish up SEH, or is there
something there that overlaps with work you've already started?

CD: 16ms