Bug 110835 - [13/14/15 Regression] -fsanitize=address causes huge runtime slowdown from std::rethrow_exception not called
Summary: [13/14/15 Regression] -fsanitize=address causes huge runtime slowdown from st...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 14.0
: P2 normal
Target Milestone: 13.4
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 112981 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-07-28 04:53 UTC by Ed Catmur
Modified: 2024-05-21 09:16 UTC (History)
9 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-07-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Catmur 2023-07-28 04:53:15 UTC
#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).

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.
Comment 1 Ed Catmur 2023-07-28 04:55:55 UTC
Motivation is https://github.com/boostorg/exception/blob/b039b4ea18ef752d0c1684b3f715ce493b778060/include/boost/exception/detail/exception_ptr.hpp#L550 ; the half-reduced code is:

#include <boost/exception_ptr.hpp>
struct S {};
int main() {
    auto ep = boost::copy_exception(S());
    for (int i = 0; i != 100000; ++i)
        try { boost::rethrow_exception(ep); } catch (...) {}
}
Comment 2 Andrew Pinski 2023-07-28 05:06:48 UTC
The code generation does not look any difference ...
So I am suspecting this was a library change.
Which might mean it is an issue in LLVM too ...
Comment 3 Andrew Pinski 2023-07-28 05:10:05 UTC
(In reply to Andrew Pinski from comment #2)
> Which might mean it is an issue in LLVM too ...

Yes the same runtime regression shows up between clang 15 and clang 16. This should reported upstream to them too.
Comment 4 Andrew Pinski 2023-07-28 05:10:45 UTC
Confirmed.
Comment 5 Andrew Pinski 2023-07-28 05:12:49 UTC
(In reply to Andrew Pinski from comment #3)
> (In reply to Andrew Pinski from comment #2)
> > Which might mean it is an issue in LLVM too ...
> 
> Yes the same runtime regression shows up between clang 15 and clang 16. This
> should reported upstream to them too.

What is interesting is that with -stdlib=libc++ the regression for clang/LLVM shows up between their 14 and 15 releases.

Anyways this should be filed upstream ...
Comment 6 Ed Catmur 2023-07-28 08:01:36 UTC
Thanks, filed https://github.com/llvm/llvm-project/issues/64190 .
Comment 7 Andrew Pinski 2023-12-12 23:12:23 UTC
*** Bug 112981 has been marked as a duplicate of this bug. ***
Comment 8 Jakub Jelinek 2024-05-21 09:16:28 UTC
GCC 13.3 is being released, retargeting bugs to GCC 13.4.