Skip to content

Commit 5951c44

Browse files
authored
[libc++] Introduce the _LIBCPP_VERBOSE_TRAP macro (#148262)
Split out the calls to __builtin_verbose_trap into a separate header. This is just a refactoring to make the code a bit more structured.
1 parent e35b01d commit 5951c44

File tree

5 files changed

+80
-12
lines changed

5 files changed

+80
-12
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ set(files
944944
__vector/vector_bool.h
945945
__vector/vector_bool_formatter.h
946946
__verbose_abort
947+
__verbose_trap
947948
algorithm
948949
any
949950
array
@@ -1569,6 +1570,7 @@ set(files
15691570
__cxx03/__utility/unreachable.h
15701571
__cxx03/__variant/monostate.h
15711572
__cxx03/__verbose_abort
1573+
__cxx03/__verbose_trap
15721574
__cxx03/algorithm
15731575
__cxx03/array
15741576
__cxx03/atomic

libcxx/include/__cxx03/__verbose_trap

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___CXX03___VERBOSE_TRAP
11+
#define _LIBCPP___CXX03___VERBOSE_TRAP
12+
13+
#include <__cxx03/__config>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
#if __has_builtin(__builtin_verbose_trap)
22+
// AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream
23+
// version before upstream Clang actually got the builtin.
24+
// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
25+
# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
26+
# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap(message)
27+
# else
28+
# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap("libc++", message)
29+
# endif
30+
#else
31+
# define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap())
32+
#endif
33+
34+
_LIBCPP_END_NAMESPACE_STD
35+
36+
#endif // _LIBCPP___CXX03___VERBOSE_TRAP

libcxx/include/__verbose_trap

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___VERBOSE_TRAP
11+
#define _LIBCPP___VERBOSE_TRAP
12+
13+
#include <__config>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
#if __has_builtin(__builtin_verbose_trap)
22+
// AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream
23+
// version before upstream Clang actually got the builtin.
24+
// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
25+
# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
26+
# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap(message)
27+
# else
28+
# define _LIBCPP_VERBOSE_TRAP(message) __builtin_verbose_trap("libc++", message)
29+
# endif
30+
#else
31+
# define _LIBCPP_VERBOSE_TRAP(message) ((void)message, __builtin_trap())
32+
#endif
33+
34+
_LIBCPP_END_NAMESPACE_STD
35+
36+
#endif // _LIBCPP___VERBOSE_TRAP

libcxx/include/module.modulemap.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,9 @@ module std [system] {
23562356
module verbose_abort {
23572357
header "__verbose_abort"
23582358
}
2359+
module verbose_trap {
2360+
header "__verbose_trap"
2361+
}
23592362
module internal_assert {
23602363
header "__assert"
23612364
export *

libcxx/vendor/llvm/default_assertion_handler.in

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1414
# include <__cxx03/__config>
1515
# include <__cxx03/__verbose_abort>
16+
# include <__cxx03/__verbose_trap>
1617
#else
1718
# include <__config>
1819
# include <__verbose_abort>
20+
# include <__verbose_trap>
1921
#endif
2022

2123
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -28,18 +30,7 @@
2830

2931
#else
3032

31-
# if __has_builtin(__builtin_verbose_trap)
32-
// AppleClang shipped a slightly different version of __builtin_verbose_trap from the upstream
33-
// version before upstream Clang actually got the builtin.
34-
// TODO: Remove once AppleClang supports the two-arguments version of the builtin.
35-
# if defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER < 1700
36-
# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap(message)
37-
# else
38-
# define _LIBCPP_ASSERTION_HANDLER(message) __builtin_verbose_trap("libc++", message)
39-
# endif
40-
# else
41-
# define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __builtin_trap())
42-
# endif
33+
# define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_TRAP(message)
4334

4435
#endif // _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
4536

0 commit comments

Comments
 (0)