C++ exceptions currently cause the shadow stack to get corrupt, because a PC can remain on the stack when the exception mechanism skips a calls to __tsan_func_exit. Besides producing wrong backtraces in reports, this also causes enormous memory usage growth in some cases.
Instead of handling exceptions at the instrumentation level, this patch tries to “fix” the shadow stack when it detects that when calling tsan_func_exit, the top of the stack contains something else than what tsan_func_entry inserted there.
Still WIP, this fails some tests (LLVM instrumentation tests, Go test and unit tests) and is missing a testcase.