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

    <tr>
        <th>Summary</th>
        <td>
            Asan with Windows EH generates __asan_xxx runtime calls without required funclet tokens
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            bug,
            compiler-rt:asan,
            platform:windows
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            sylvain-audi
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          sylvain-audi
      </td>
    </tr>
</table>

<pre>
    This issue has been discussed in #39667 as well as https://github.com/google/sanitizers/issues/749

As mentionned by @rnk in a comment: "ASan instrumentation isn't inserting calls into EH pads with the right funclet token bundle, so any attempts to do ASan checks inside funclets will be removed by WinEHPrepare. "

It seems that not only WinEHPrepare will remove the calls themselves but it also discards the entire Basic Block around it, replacing the content with `unreachable` statement. 

Here is a repro: 
```
char buff1[6] = "hello";
char buff2[6] = "hello";

int main(int argc, char **argv) {
  int result = 1;
  try {
    throw 1;
  } catch (...) {
    // make asan generate call to __asan_memcpy that should report an error due to memory overflow.
    __builtin_memcpy(buff1, buff2 + 3, 6);
    result = 0;
  }
  return result;
}
```

See in Compiler Explorer: https://godbolt.org/z/Tacdhsz4T
Notice, in the `LLVM Opt Pipeline Viewer`, the `WinEHPrepare` pass of `main`:  the entire `catch` Basic block and successors get transformed into a single `unreachable` statement.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVVFv2zgM_jXKC9HAlR27fshD2q7YAbu7ARu2x4K2GVtXWfKJVNLs1x9kJ1vahx0QOLZEfSQ_8qOQ2fSOaKs290prPtkDGneDsTNKa7V5XGGUwYft9c6q8d1p-3UwDIY5EgzI0BA56Ay3kZk6MA6UzvO6LCtAhiNZm_4HkYlVvlP6Semn3sgQm3Xrx_ThfW9J6SdGZ8T8oMBKP80O0ktV1Cp7VNluee4YRnJivHPUQXMCVWTBvSS_CK0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