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

    <tr>
        <th>Summary</th>
        <td>
            Register not restored after inline ASM clobber with 32-bit Windows exceptions
        </td>
    </tr>

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

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

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

<pre>
    Code:
```c++
// clang -target i686-pc-win32 -c clangbug.cpp
#include <stdint.h>

class UnwindDtor {
public:
    ~UnwindDtor();
    uint64_t val;
};

void repro() {
    UnwindDtor a;
    __asm__ volatile("nop"::"S"(0xDEADBEEF));
    a.val = 1;
 throw;
}
```

LLVM IR output: https://godbolt.org/z/3do1G586K

Clang moves `esp` to `esi` and uses it to access the stack, but it doesn't restore `esi` after it gets clobbered by being an inline ASM input.

```
mov     esi, -559038737
nop
mov     dword ptr [esi + 12], 0
mov     dword ptr [esi + 8], 1
mov     dword ptr [esi + 32], 0
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVE2P2zYQ_TXUZWBDIq0PH3SwV-uiaHJJ0PZo8GMssaFJQRzZSQ_97QVlZ-3dUwCCNvnevHnkIyRjtL1HbFm5Z2WXyZmGMLXfBun7vMpUMD_al2CQiR3LO5bvWJXfhmZ8n8Ztlx8YP4B20vewIjn1SGCrplqNenW1XnBY6Rus5n6tx_FnnbBeu9kgMPESyVhP64GJ1zu8zNrJGOFPf7XedBQmYPW97TgrZ_WbNwCA_x48xhvGt0zsH-hsPVWbI8FFujeA1d3j_zJfgjUw4TiFm8ajYxJ5ciLfqR-PMp6PR7gEJ8k6XIq5DyPjPJkUO8b517TgTf69e911-9fXQ_L4waZcX6QDJjooHvs0TOH6zvT7QJ4P8OnTX5_h9y8QZhpnYmIHA9EYFwcpqT4YFRytw9QzfviX8YMwofitbKo_nmVeljzP4YIRWJVjHFmVA4XbwqaF9AbmiBEsJUBqjTECDQiRpP7G-AuomRJqAkbPeE0wYaQw4bPKiXBKpB4pgnZBKZzQgPoBCq3vQXqw3lmPsPv6GawfZ1o_O_1wC-dwSfcISZ6_wKost7loalHf4BTJO565hsnASBOwco_RAuN7KDgru1Se_wK5uXOLX-CKD8Jv5jPTCrMVW5lhW9R5XYlNUdfZ0CKvT0pigRt9EuXGNKqpsWqUVrlpKl1ntuU53-S8KPJqsxX1eivrU90ILhDzU9nUbJPjWVq3du5yTrlnNsYZ26YQ2zJzUqGLy0eAc49XWMD0Ussum9pUs1JzH9kmdzZSfKiQJYftF-xtTBH68Bav-ZnqI7d7sHC1NIDgK2UJ_rbehGsE_K5xJBt8zObJtR_eq6VhVmsdzowfUu_7z2qcwj-oifHD4jgyflhO9H8AAAD__7JvZwg">