[PATCH] D80344: [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1

John McCall via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 16:41:38 PDT 2020


rjmccall added a comment.

In D80344#2293954 <https://reviews.llvm.org/D80344#2293954>, @tentzen wrote:

> In D80344#2291926 <https://reviews.llvm.org/D80344#2291926>, @rjmccall wrote:
>
>> Okay.  I think we're on the same page about representation now.  If you can come up with a good replacement for "eha" in the intrinsic names, I think this is pretty much ready to go.
>
> how about seh.cppscope.begin() and seh.cppscope.end()? or any suggestion?

I like that better.  Maybe even just `seh.scope.begin`?  Or `seh.cleanupscope.begin`?  Cleanups aren't *inherently* a C++ feature, it's just that C doesn't officially have them and MSVC doesn't really support any non-C++ languages that do.

> As for pairing question, we simply utilizes existent Cleanup mechanism as you described in which abnormal exits and normal fall-through are merged in a 'cleanup' pad.  What this implementation does is to inject a scope.begin right after a ctor and a scope.end right before dtor in cleanup-pad.  Use the same example, it will be something like below:
>
>   void test(int x, int &state) {
>     int jumpdest;
>     state = 0;
>     std::string a;  
>     **seh.cppscope.begin();  // for object a**
>     state = 1;
>     if (x > 0) {
>       state = 2;
>       std::string b;
>       **seh.cppscope.begin();  // for b**
>       state = 3;
>       if (x > 10) {
>         state = 4;
>         jumpdest = 0;
>         goto destroy_b;
>       }
>       state = 5;
>       std::string c;
>       **seh.cppscope.begin();  // for c**
>       state = 6;
>       **seh.cppscope.end(); // for c dtor**
>       c.~std::string();
>       jumpdest = 1;
>     destroy_b:
>       **seh.cppscope.end();   // for b dtor**
>       b.~std::string();
>       switch (jumpdest) {
>       case 0: goto destroy_a;
>       case 1: goto fallthrough;
>       }
>     fallthrough:
>       ;
>     }
>     state = 7;
>   destroy_a:
>     **seh.cppscope.begin();  // for a dtor **
>     a.~std::string();
>   }

Okay.  I feel fairly convinced that this will work for most cleanup situations.  You might need to do some IR-testing work in Clang to make sure Clang calls seh.scope.begin the right way when emitting conditional cleanups:

- We need to call it at some dominating point rather than at the current IP when we push the cleanup.
- We need to call it in the right order for the cleanups we enter.

Conditional cleanups come up when we need a cleanup in code that's not unconditionally run during a expression evaluation, like in the 2nd or 3rd operand of `?:` or in the RHS of `&&`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80344/new/

https://reviews.llvm.org/D80344



More information about the llvm-commits mailing list