[all-commits] [llvm/llvm-project] b0fd94: [libc++] Add a lightweight overridable assertion h...

Louis Dionne via All-commits all-commits at lists.llvm.org
Wed Mar 23 12:36:25 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b0fd9497af6d2efd305e9eecfa0c1e265f1b2192
      https://github.com/llvm/llvm-project/commit/b0fd9497af6d2efd305e9eecfa0c1e265f1b2192
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2022-03-23 (Wed, 23 Mar 2022)

  Changed paths:
    M libcxx/CMakeLists.txt
    M libcxx/cmake/caches/Generic-assertions.cmake
    M libcxx/docs/BuildingLibcxx.rst
    M libcxx/docs/ReleaseNotes.rst
    M libcxx/docs/UsingLibcxx.rst
    M libcxx/include/__assert
    M libcxx/include/__availability
    M libcxx/include/__config_site.in
    M libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.debug.incomplete.abilist
    M libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.nodebug.noincomplete.abilist
    M libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.debug.incomplete.abilist
    M libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.nodebug.noincomplete.abilist
    M libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.debug.incomplete.abilist
    M libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.debug.noincomplete.abilist
    M libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.nodebug.incomplete.abilist
    M libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.debug.incomplete.abilist
    M libcxx/src/CMakeLists.txt
    M libcxx/src/assert.cpp
    A libcxx/src/legacy_debug_handler.cpp
    A libcxx/test/libcxx/assertions/assertions_disabled.pass.cpp
    A libcxx/test/libcxx/assertions/customize_handler.backdeployment.pass.cpp
    A libcxx/test/libcxx/assertions/customize_handler.pass.cpp
    A libcxx/test/libcxx/assertions/debug_mode_compatibility.pass.cpp
    A libcxx/test/libcxx/assertions/default_handler.abort.pass.cpp
    A libcxx/test/libcxx/assertions/default_handler.availability.verify.cpp
    M libcxx/test/libcxx/containers/sequences/array/array.zero/assert.back.pass.cpp
    M libcxx/test/libcxx/containers/sequences/array/array.zero/assert.front.pass.cpp
    M libcxx/test/libcxx/containers/sequences/array/array.zero/assert.subscript.pass.cpp
    M libcxx/test/libcxx/containers/sequences/deque/assert.pop_back.empty.pass.cpp
    M libcxx/test/libcxx/containers/sequences/list/list.modifiers/assert.erase_iter.end.pass.cpp
    M libcxx/test/libcxx/containers/sequences/list/list.modifiers/assert.pop_back.empty.pass.cpp
    M libcxx/test/libcxx/containers/sequences/vector/assert.back.empty.pass.cpp
    M libcxx/test/libcxx/containers/sequences/vector/assert.cback.empty.pass.cpp
    M libcxx/test/libcxx/containers/sequences/vector/assert.cfront.empty.pass.cpp
    M libcxx/test/libcxx/containers/sequences/vector/assert.cindex.oob.pass.cpp
    M libcxx/test/libcxx/containers/sequences/vector/assert.front.empty.pass.cpp
    M libcxx/test/libcxx/containers/sequences/vector/assert.index.oob.pass.cpp
    M libcxx/test/libcxx/containers/sequences/vector/assert.pop_back.empty.pass.cpp
    M libcxx/test/libcxx/containers/sequences/vector/robust_against_adl.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.map/assert.bucket.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.map/assert.bucket_size.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.map/assert.max_load_factor.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.multimap/assert.bucket.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.multimap/assert.bucket_size.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.multimap/assert.max_load_factor.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.multiset/assert.bucket.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.multiset/assert.bucket_size.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.multiset/assert.max_load_factor.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.set/assert.bucket.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.set/assert.bucket_size.pass.cpp
    M libcxx/test/libcxx/containers/unord/unord.set/assert.max_load_factor.pass.cpp
    R libcxx/test/libcxx/debug/check_assertion_test.pass.cpp
    M libcxx/test/libcxx/debug/containers/string.pass.cpp
    R libcxx/test/libcxx/debug/debug_abort.pass.cpp
    R libcxx/test/libcxx/debug/register_debug_handler.pass.cpp
    M libcxx/test/libcxx/experimental/memory/memory.polymorphic.allocator.class/memory.polymorphic.allocator.mem/assert.deallocate.pass.cpp
    M libcxx/test/libcxx/experimental/memory/memory.resource.adaptor/memory.resource.adaptor.mem/assert.deallocate.pass.cpp
    M libcxx/test/libcxx/input.output/filesystems/class.path/path.itr/assert.iterator.pass.cpp
    M libcxx/test/libcxx/iterators/assert.advance.pass.cpp
    M libcxx/test/libcxx/iterators/assert.next.pass.cpp
    M libcxx/test/libcxx/iterators/assert.prev.pass.cpp
    M libcxx/test/libcxx/strings/basic.string/string.access/assert.back.pass.cpp
    M libcxx/test/libcxx/strings/basic.string/string.access/assert.cback.pass.cpp
    M libcxx/test/libcxx/strings/basic.string/string.access/assert.cfront.pass.cpp
    M libcxx/test/libcxx/strings/basic.string/string.access/assert.cindex.pass.cpp
    M libcxx/test/libcxx/strings/basic.string/string.access/assert.front.pass.cpp
    M libcxx/test/libcxx/strings/basic.string/string.access/assert.index.pass.cpp
    M libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.erase_iter.null.pass.cpp
    M libcxx/test/libcxx/strings/basic.string/string.modifiers/assert.pop_back.pass.cpp
    M libcxx/test/libcxx/strings/string.view/assert.ctor.pointer.pass.cpp
    M libcxx/test/libcxx/thread/futures/futures.promise/assert.set_exception.pass.cpp
    M libcxx/test/libcxx/thread/futures/futures.promise/assert.set_exception_at_thread_exit.pass.cpp
    M libcxx/test/libcxx/utilities/optional/optional.object/optional.object.observe/assert.dereference.pass.cpp
    M libcxx/test/libcxx/utilities/optional/optional.object/optional.object.observe/assert.op_arrow.pass.cpp
    M libcxx/test/support/check_assertion.h
    A libcxx/test/support/test.support/test_check_assertion.pass.cpp
    M libcxx/utils/libcxx/test/params.py

  Log Message:
  -----------
  [libc++] Add a lightweight overridable assertion handler

This patch adds a lightweight assertion handler mechanism that can be
overriden at link-time in a fashion similar to `operator new`.

This is a third take on https://llvm.org/D121123 (which allowed customizing
the assertion handler at compile-time), and https://llvm.org/D119969
(which allowed customizing the assertion handler at runtime only).

This approach is, I think, the best of all three explored approaches.
Indeed, replacing the assertion handler in user code is ergonomic,
yet we retain the ability to provide a custom assertion handler when
deploying to older platforms that don't have a default handler in
the dylib.

As-is, this patch provides a pretty good amount of backwards compatibility
with the previous debug mode:

- Code that used to set _LIBCPP_DEBUG=0 in order to get basic assertions
  in their code will still get basic assertions out of the box, but
  those assertions will be using the new assertion handler support.
- Code that was previously compiled with references to __libcpp_debug_function
  and friends will work out-of-the-box, no changes required. This is
  because we provide the same symbols in the dylib as we used to.
- Code that used to set a custom __libcpp_debug_function will stop
  compiling, because we don't provide that declaration anymore. Users
  will have to migrate to the new way of setting a custom assertion
  handler, which is extremely easy. I suspect that pool of users is
  very limited, so breaking them at compile-time is probably acceptable.

The main downside of this approach is that code being compiled with
assertions enabled but deploying to an older platform where the assertion
handler didn't exist yet will fail to compile. However users can easily
fix the problem by providing a custom assertion handler and defining
the _LIBCPP_AVAILABILITY_CUSTOM_ASSERTION_HANDLER_PROVIDED macro to
let the library know about the custom handler. In a way, this is
actually a feature because it avoids a load-time error that one would
otherwise get when trying to run the code on the older target.

Differential Revision: https://reviews.llvm.org/D121478




More information about the All-commits mailing list