[libcxx-commits] [PATCH] D66177: Update shared_ptr's constructor

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 22 15:54:12 PDT 2019


zoecarver marked an inline comment as done.
zoecarver added inline comments.


================
Comment at: libcxx/include/memory:3979
+    : __ptr_(__p),
+      __cntrl_(__allocate_shared(__p))
 {
----------------
ldionne wrote:
> Before, we would create the control block with `new`, and with this patch we're using the allocator. Is this correct? Why?
> 
> Also, we're now unconditionally using a try-catch block -- I'd be curious to see what the impact on code generation is.
Yes, it's correct. The allocator will call `__builtin_operator_new` (or `operator new`), which makes it functionally equivalent. When the control block is deallocated, it calls `__a.deallocate`. I think it's better that the control block is also allocated with the allocator (even if they're functionally equivalent) both for cognitive load and in case we introduced an optimization (for example) that broke this type of deallocation down the road. 

I'll take a look at the codegen. 


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D66177





More information about the libcxx-commits mailing list