[libcxx-commits] [PATCH] D128146: [libc++] Use uninitialized algorithms for vector

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jul 26 06:29:57 PDT 2022


ldionne added inline comments.


================
Comment at: libcxx/include/__memory/uninitialized_algorithms.h:533-534
+  auto __destruct_first = __first2;
+  auto __guard =
+      std::__make_transaction(_AllocatorDestroyRangeReverse<_Alloc, _Iter2>(__alloc, __destruct_first, __first2));
+#ifndef _LIBCPP_NO_EXCEPTIONS
----------------
@philnik Since they say they use `-fno-exceptions`, I assume the issue is that `std::__transaction` doesn't get optimized away for when exceptions are disabled (which would make sense because they are probably compiling with lower optimization levels too).

Instead, we could use

```
#ifndef _LIBCPP_NO_EXCEPTIONS
  try {
#endif
    while (__first1 != __last1) {
        allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__first2), *__first1);
        ++__first1;
        ++__first2;
        
    }
#ifndef _LIBCPP_NO_EXCEPTIONS
  } catch (...) {
    std::__allocator_destroy(__alloc_, std::reverse_iterator<_Iter>(__first2), std::reverse_iterator<_Iter>(__destruct_first));
    throw;
  }
#endif
```

And ditch `__transaction` altogether. We can then look into improving codegen with `__transaction` separately. Under `-fno-exception`, the code above should be reallly close to what we had before.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128146/new/

https://reviews.llvm.org/D128146



More information about the libcxx-commits mailing list