[libcxx-commits] [PATCH] D95827: Avoid cast<T*> before T is constructed to pacify CFI checks

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 1 15:30:06 PST 2021


ldionne added a comment.

Ah, I just commented on the bug report, but your patch confirms what I thought. Thanks for the patch. So this is basically a CFI false positive, do we agree?

Another approach would be:

  template <class _Pointer = _Tp*>
  _Pointer __get_elem() _NOEXCEPT {
      _CompressedPair *__as_pair = reinterpret_cast<_CompressedPair*>(__blob_);
      typename _CompressedPair::_Base2* __second = _CompressedPair::__get_second_base(__as_pair);
      _Pointer __elem = reinterpret_cast<_Pointer>(__second);
      return __elem;
  }

Then, we can use it as `__get_elem<void*>()` for the placement-new use case, and just `__get_elem()` for the normal case. What do you think?



================
Comment at: libcxx/include/memory:2656
         }
+	void *__get_elem_for_new() _NOEXCEPT {
+            _CompressedPair *__as_pair = reinterpret_cast<_CompressedPair*>(__blob_);
----------------
Indentation looks off.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95827



More information about the libcxx-commits mailing list