@@ -18,4 +18,37 @@ void bm_make_exception_ptr(benchmark::State& state) {
1818}
1919BENCHMARK (bm_make_exception_ptr)->ThreadRange(1 , 8 );
2020
21+ static bool exception_ptr_moves_copies_swap (std::exception_ptr p1) {
22+ // Taken from https://github.com/llvm/llvm-project/issues/44892
23+ std::exception_ptr p2 (p1); // Copy constructor
24+ std::exception_ptr p3 (std::move (p2)); // Move constructor
25+ p2 = std::move (p1); // Move assignment
26+ p1 = p2; // Copy assignment
27+ swap (p1, p2); // Swap
28+ // Comparisons against nullptr. The overhead from creating temporary `exception_ptr`
29+ // instances should be optimized out.
30+ bool is_null = p1 == nullptr && nullptr == p2;
31+ bool is_equal = p1 == p2; // Comparison
32+ return is_null && is_equal;
33+ }
34+
35+ void bm_empty_exception_ptr (benchmark::State& state) {
36+ for (auto _ : state) {
37+ // All of the `exception_ptr_noops` are no-ops because
38+ // the exception_ptr is empty. Hence, the compiler should
39+ // be able to optimize them very aggressively.
40+ benchmark::DoNotOptimize (exception_ptr_moves_copies_swap (std::exception_ptr{nullptr }));
41+ }
42+ }
43+ BENCHMARK (bm_empty_exception_ptr);
44+
45+ void bm_exception_ptr (benchmark::State& state) {
46+ std::exception_ptr excptr = std::make_exception_ptr (42 );
47+ for (auto _ : state) {
48+ benchmark::DoNotOptimize (excptr);
49+ benchmark::DoNotOptimize (exception_ptr_moves_copies_swap (excptr));
50+ }
51+ }
52+ BENCHMARK (bm_exception_ptr);
53+
2154BENCHMARK_MAIN ();
0 commit comments