[PATCH] D102817: [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 2

Ten Tzen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 29 23:14:02 PST 2021


tentzen added a comment.

Hi Joseph, all good points. see replies below.
thank you!



================
Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:2887-2888
     case Intrinsic::seh_try_end:
     case Intrinsic::seh_scope_end:
+      if (CleanupMBB) // a CleanupPad, referenced by EH table
+        CleanupMBB->setHasAddressTaken(); // so dtor-funclet not removed by opts
----------------
JosephTremoulet wrote:
> tentzen wrote:
> > JosephTremoulet wrote:
> > > How do we know that this is a CleanupPad and not a Catchswitch?
> > fixed. thanks.
> Nit: variable name still indicates cleanup.  I'd suggest `EHPadMBB`.
good catch. will fix it. thanks.


================
Comment at: llvm/lib/CodeGen/WinEHPrepare.cpp:267-269
+//   Side exits can ONLY jump into parent scopes (lower state number).
+//   Thus, when a block succeeds various states from its predecessors,
+//     the lowest State triumphs others.
----------------
JosephTremoulet wrote:
> tentzen wrote:
> > JosephTremoulet wrote:
> > > I think you're saying here that it's legal for a side exit to target a successor with any ancestor state.  But also you're assigning each such successor the exact parent state of its least predecessor ("least" by comparing state numbers).  How do you know that it shouldn't be the grandparent (or any other ancestor) of the least predecessor?
> > the new state only assigned to successor when it's smaller than successor's current state.  See the first line in the while loop. 
> > if ( ... && EHInfo.BlockToStateMap[BB] <= State) ..
> Yes I see that you're taking the state of the least connected predecessor.  What I'm not following is how you know that the least connected predecessor is a sibling, rather than say a neice -- what if the sibling ends in unreached, for example?  Something like:
> 
> ```
> B1: (state = 0
> { // new scope
> B2: (state = 1)
>   { // new scope
>   B2: (state = 2)
>      { // new scope
>      B3: (state = 3)
>         if (_) {
>         B4:
>             goto B7;
>         }
>         B5: (state = 3)
>         __assume(0);
>      } // exit scope
>      B6: (state TBD)
>   } // exit scope
>  B7: (state TBD)
> } // exit scope
> B8: (state TBD)
> ```
> 
> And maybe optimization turned __assume(0) into unreachable and got rid of B6 entirely.  So then B4 is the only predecessor of B7.  Doesn't that mean we'll assign state 2 to B7?  But B7 should have state 1.  How do we know this doesn't happen?
> 
> 
>   
Very good point. In this case, B7 actually is a side-entry that is led by a block of seh_scope_begin() intrinsic (see CpodeGen/CGStmt.cpp change in Part-1 patch).  As such, the state will be reset via EHInfo.InvokeStateMap[] when real code blocks are proceeded. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102817



More information about the llvm-commits mailing list