Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libcxx/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ set(files
__vector/vector_bool.h
__vector/vector_bool_formatter.h
__verbose_abort
__verbose_trap
algorithm
any
array
Expand Down Expand Up @@ -1569,6 +1570,7 @@ set(files
__cxx03/__utility/unreachable.h
__cxx03/__variant/monostate.h
__cxx03/__verbose_abort
__cxx03/__verbose_trap
__cxx03/algorithm
__cxx03/array
__cxx03/atomic
Expand Down
36 changes: 36 additions & 0 deletions libcxx/include/__cxx03/__verbose_trap
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___CXX03___VERBOSE_TRAP
#define _LIBCPP___CXX03___VERBOSE_TRAP

#include <__cxx03/__config>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_builtin(__builtin_verbose_trap)
// AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream
// version before upstream Clang actually got the builtin.
// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap(message)
# else
# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap("libc++", message)
# endif
#else
# define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap())
#endif

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___CXX03___VERBOSE_TRAP
36 changes: 36 additions & 0 deletions libcxx/include/__verbose_trap
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _LIBCPP___VERBOSE_TRAP
#define _LIBCPP___VERBOSE_TRAP

#include <__config>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

#if __has_builtin(__builtin_verbose_trap)
// AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream
// version before upstream Clang actually got the builtin.
// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap(message)
# else
# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap("libc++", message)
# endif
#else
# define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap())
#endif

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___VERBOSE_TRAP
3 changes: 3 additions & 0 deletions libcxx/include/module.modulemap.in
Original file line number Diff line number Diff line change
Expand Up @@ -2356,6 +2356,9 @@ module std [system] {
module verbose_abort {
header "__verbose_abort"
}
module verbose_trap {
header "__verbose_trap"
}
module internal_assert {
header "__assert"
export *
Expand Down
15 changes: 3 additions & 12 deletions libcxx/vendor/llvm/default_assertion_handler.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
# include <__cxx03/__config>
# include <__cxx03/__verbose_abort>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: what do we do about the frozen headers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question, and actually it's not easy to answer IMO. CCing @philnik777 .

I see a few options:

  1. Introduce <__cxx03/__verbose_trap>. This seems to go against the notion of having "frozen headers".
  2. Define _LIBCPP_VERBOSE_TRAP inline inside default_assertion_handler.in inside this #if block. This is equivalent to (1) except we don't introduce a new header under __cxx03.
  3. Always use the non-C++03 headers from default_assertion_handler.in. So this means get rid of the #if and always include <__config> and <__verbose_abort>, never their <__cxx03/...> counterparts. This would be doable since <__verbose_abort> doesn't actually need C++11, but it goes against the principle of the split and may cause other conflicts if we somehow end up including both <__config> and <__cxx03/__config>.
  4. Have two copies of default_assertion_handler.in, one normal and one for the frozen headers. This is a bit tricky since default_assertion_handler.in is something we set up from CMake and expect vendors to be able to override.

I think (1) is the best outcome here. We'll have to support these hardening improvements in frozen-C++03 anyways otherwise this'll be a regression in functionality.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comprehensive overview of alternatives, this is super useful!

From what I gather, the frozen headers are still undergoing development, so them being completely frozen is the end goal rather than a description of the current state. If that perspective is valid, I also think that option (1) is the best, or at least the lesser evil out of the available options.

# include <__cxx03/__verbose_trap>
#else
# include <__config>
# include <__verbose_abort>
# include <__verbose_trap>
#endif

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Expand All @@ -28,18 +30,7 @@

#else

# if __has_builtin(__builtin_verbose_trap)
// AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream
// version before upstream Clang actually got the builtin.
// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap(message)
# else
# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap("libc++", message)
# endif
# else
# define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())
# endif
# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_TRAP(message)

#endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG

Expand Down
Loading