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

    <tr>
        <th>Summary</th>
        <td>
            -fsanitize=address causes huge runtime slowdown from std::rethrow_exception not called
        </td>
    </tr>

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

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

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

<pre>
    ```c++
#include <exception>
std::exception_ptr p;
void f() {
  try { throw 1; } catch(char) { std::rethrow_exception(p); }
}
int main() {
  for (int i = 0; i != 100000; ++i)
    try { f(); } catch (...) { }
}
```

Compiled with -fsanitize=address (and at -O0 through -O3), this is roughly 30x slower under gcc 13 than under gcc 12 (4.7s vs 0.15s on my Core i7 3 GHz).

On godbolt with clang/libc++ and clang/libstdc++ both the problem exhibits between clang 14.0.0 and clang 15.0.0. At -O1 clang appears capable of enough elision to reduce the impact somewhat (so it is only ~15x slower) and at -O3 to eliminate the bug entirely.

Initially reported to gcc at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110835 but they pointed out that it appears to be a bug in compiler-rt/asan, not in the compiler.

Note that the std::rethrow_exception() is not called, but is still essential to exhibit the bug. Also `f` needs to be a separate function (and not `static`). At low optimization levels it can be an iife.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VM2O4zYMfhrlQsSQpTg_Bx9mJ03bS_cRFrLM2CxkyZDoyWQOffZCSjI_3WIDIYlI8ePHj5RMSjR4xFY030RzXJmFxxBbtIanJa660F9bsZW3ZYX6lpc8CvkklCZv3dIjCP2MrxZnpuCF_u3mT9wL_ST007vrx8wRZqHvAC-BejgLtRfqAGJ3twJwvOYt8BjDBWqhv4HYHcEatqNQezuaeI-A9xwRy-kfHzTUfhbqcA--M378Ic8wGfI_5z6HCELt8wECoY8gMwKBUHXe1TJ_CmhRgnKKe-g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