<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/54922>54922</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [SEH] Scopes shouldn't end on a call instruction
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          namazso
      </td>
    </tr>
</table>

<pre>
    `call` is a special instruction for SEH, as exceptions thrown in a lower frame manifest at the return address (ie the end of the call instruction), rather than the start of it. This means that SEH ranges must always cover the end of the `call` instruction. This is all fine and working, however this range will also accidentally catch exceptions raised by the next instruction, that is code-wise outside the range. Here's an example:

```cpp
#include <intrin.h>
#include <cstdio>

__declspec(noinline) void do_nothing() {}
__declspec(noinline) void test()
{
        __try {
                do_nothing();
        } __except(1) {
                printf("hello\n");
        }
        __debugbreak();
}
int main()
{
        __try {
                test();
        } __except(1) {
                printf("world\n");
        }
        return 0;
}
```

This will print "hello" in an infinite loop on LLVM 14.0. This is because the `int3` is erroneously caught by the `__try`

The way MSVC solves this is by inserting a nop after a call that falls on the end of a SEH scope range. Some more discussion on related matters can be found in #46803
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVMuO2zoM_RpnQzRw5DzGCy9ukxZdtKspug1kiY7VKpIhypOmX19KTmbcToHeewHDccTHOaR42Hp9bYptqaS1_AOGQAINqIy0YBzFMKpovIPOB3h896EQe5AE-F3hkM4JYh_8xbEvB1p_wQBdkGeEs3SmQ4ogI_sgBIxjYCetAxJBIR4MZgM6Db7Ln4nFHLUQdQIMko2BPaTLbhRliCnGxCV87pnzGWWmwlhMkgPcCfl0TPD2Iq8Eyj_lFL_gzQt_Qb3lTK1gOp1xCJJjLj58M-6UCPVc55SOnTIYXAz7SksepFJGo4scfOWKourn7QrSEGpor5mAw-_x14L3UxUmMdb45sLe4MdInHJqY0Jbwg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