Skip to content

Commit c1dc764

Browse files
committed
[libc++][NFC] Move QoI attributes into a single place inside <__config>
1 parent 42204c9 commit c1dc764

File tree

1 file changed

+128
-122
lines changed

1 file changed

+128
-122
lines changed

libcxx/include/__config

Lines changed: 128 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,6 @@ _LIBCPP_HARDENING_MODE_DEBUG
552552
# define _LIBCPP_USING_DEV_RANDOM
553553
# endif
554554

555-
# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
556-
# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
557-
# else
558-
# define _LIBCPP_NO_CFI
559-
# endif
560-
561555
# ifndef _LIBCPP_CXX03_LANG
562556

563557
# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
@@ -629,11 +623,6 @@ typedef __char32_t char32_t;
629623
# define _LIBCPP_HAS_NO_ASAN
630624
# endif
631625

632-
// Allow for build-time disabling of unsigned integer sanitization
633-
# if __has_attribute(no_sanitize)
634-
# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
635-
# endif
636-
637626
# define _LIBCPP_ALWAYS_INLINE __attribute__((__always_inline__))
638627

639628
# define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
@@ -859,18 +848,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
859848
# define _LIBCPP_HAS_NO_INT128
860849
# endif
861850

862-
# if __has_attribute(__malloc__)
863-
# define _LIBCPP_NOALIAS __attribute__((__malloc__))
864-
# else
865-
# define _LIBCPP_NOALIAS
866-
# endif
867-
868-
# if __has_attribute(__using_if_exists__)
869-
# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
870-
# else
871-
# define _LIBCPP_USING_IF_EXISTS
872-
# endif
873-
874851
# ifdef _LIBCPP_CXX03_LANG
875852
# define _LIBCPP_DECLARE_STRONG_ENUM(x) \
876853
struct _LIBCPP_EXPORTED_FROM_ABI x { \
@@ -1040,29 +1017,6 @@ _LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
10401017
# define _LIBCPP_CONSTEXPR_SINCE_CXX23
10411018
# endif
10421019

1043-
# if __has_cpp_attribute(nodiscard)
1044-
# define _LIBCPP_NODISCARD [[__nodiscard__]]
1045-
# else
1046-
// We can't use GCC's [[gnu::warn_unused_result]] and
1047-
// __attribute__((warn_unused_result)), because GCC does not silence them via
1048-
// (void) cast.
1049-
# define _LIBCPP_NODISCARD
1050-
# endif
1051-
1052-
// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
1053-
// specified as such as an extension.
1054-
# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1055-
# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
1056-
# else
1057-
# define _LIBCPP_NODISCARD_EXT
1058-
# endif
1059-
1060-
# if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1061-
# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
1062-
# else
1063-
# define _LIBCPP_NODISCARD_AFTER_CXX17
1064-
# endif
1065-
10661020
# ifndef _LIBCPP_HAS_NO_ASAN
10671021
extern "C" _LIBCPP_EXPORTED_FROM_ABI void
10681022
__sanitizer_annotate_contiguous_container(const void*, const void*, const void*, const void*);
@@ -1198,10 +1152,6 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
11981152
# endif
11991153
# endif
12001154

1201-
# ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1202-
# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1203-
# endif
1204-
12051155
# if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(__no_thread_safety_analysis__)
12061156
# define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((__no_thread_safety_analysis__))
12071157
# else
@@ -1234,51 +1184,6 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
12341184
# define _LIBCPP_CONSTINIT
12351185
# endif
12361186

1237-
# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1238-
# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1239-
# else
1240-
# define _LIBCPP_DIAGNOSE_WARNING(...)
1241-
# endif
1242-
1243-
// Use a function like macro to imply that it must be followed by a semicolon
1244-
# if __has_cpp_attribute(fallthrough)
1245-
# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1246-
# elif __has_attribute(__fallthrough__)
1247-
# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1248-
# else
1249-
# define _LIBCPP_FALLTHROUGH() ((void)0)
1250-
# endif
1251-
1252-
# if __has_cpp_attribute(_Clang::__lifetimebound__)
1253-
# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1254-
# else
1255-
# define _LIBCPP_LIFETIMEBOUND
1256-
# endif
1257-
1258-
# if __has_attribute(__nodebug__)
1259-
# define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1260-
# else
1261-
# define _LIBCPP_NODEBUG
1262-
# endif
1263-
1264-
# if __has_attribute(__standalone_debug__)
1265-
# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1266-
# else
1267-
# define _LIBCPP_STANDALONE_DEBUG
1268-
# endif
1269-
1270-
# if __has_attribute(__preferred_name__)
1271-
# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1272-
# else
1273-
# define _LIBCPP_PREFERRED_NAME(x)
1274-
# endif
1275-
1276-
# if __has_attribute(__no_sanitize__)
1277-
# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1278-
# else
1279-
# define _LIBCPP_NO_SANITIZE(...)
1280-
# endif
1281-
12821187
// We often repeat things just for handling wide characters in the library.
12831188
// When wide characters are disabled, it can be useful to have a quick way of
12841189
// disabling it without having to resort to #if-#endif, which has a larger
@@ -1289,12 +1194,6 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
12891194
# define _LIBCPP_IF_WIDE_CHARACTERS(...) __VA_ARGS__
12901195
# endif
12911196

1292-
# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1293-
# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1294-
# else
1295-
# define _LIBCPP_DECLSPEC_EMPTY_BASES
1296-
# endif
1297-
12981197
# if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
12991198
# define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
13001199
# define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
@@ -1338,21 +1237,6 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
13381237
# define _LIBCPP_FOPEN_CLOEXEC_MODE
13391238
# endif
13401239

1341-
# if __has_attribute(__init_priority__)
1342-
# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1343-
# else
1344-
# define _LIBCPP_INIT_PRIORITY_MAX
1345-
# endif
1346-
1347-
# if __has_attribute(__format__)
1348-
// The attribute uses 1-based indices for ordinary and static member functions.
1349-
// The attribute uses 2-based indices for non-static member functions.
1350-
# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1351-
__attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1352-
# else
1353-
# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1354-
# endif
1355-
13561240
# if __has_cpp_attribute(msvc::no_unique_address)
13571241
// MSVC implements [[no_unique_address]] as a silent no-op currently.
13581242
// (If/when MSVC breaks its C++ ABI, it will be changed to work as intended.)
@@ -1392,12 +1276,6 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
13921276
# define _LIBCPP_GCC_DIAGNOSTIC_IGNORED(str)
13931277
# endif
13941278

1395-
# if __has_attribute(__packed__)
1396-
# define _LIBCPP_PACKED __attribute__((__packed__))
1397-
# else
1398-
# define _LIBCPP_PACKED
1399-
# endif
1400-
14011279
// c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
14021280
// functions is gradually being added to existing C libraries. The conditions
14031281
// below check for known C library versions and conditions under which these
@@ -1486,6 +1364,134 @@ __sanitizer_verify_double_ended_contiguous_container(const void*, const void*, c
14861364

14871365
# define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
14881366

1367+
// Optional attributes - these are useful for a better QoI, but not required to be available
1368+
1369+
# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
1370+
# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
1371+
# else
1372+
# define _LIBCPP_NO_CFI
1373+
# endif
1374+
1375+
# if __has_attribute(__malloc__)
1376+
# define _LIBCPP_NOALIAS __attribute__((__malloc__))
1377+
# else
1378+
# define _LIBCPP_NOALIAS
1379+
# endif
1380+
1381+
# if __has_attribute(__using_if_exists__)
1382+
# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
1383+
# else
1384+
# define _LIBCPP_USING_IF_EXISTS
1385+
# endif
1386+
1387+
# if __has_cpp_attribute(nodiscard)
1388+
# define _LIBCPP_NODISCARD [[__nodiscard__]]
1389+
# else
1390+
// We can't use GCC's [[gnu::warn_unused_result]] and
1391+
// __attribute__((warn_unused_result)), because GCC does not silence them via
1392+
// (void) cast.
1393+
# define _LIBCPP_NODISCARD
1394+
# endif
1395+
1396+
// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
1397+
// specified as such as an extension.
1398+
# if !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1399+
# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD
1400+
# else
1401+
# define _LIBCPP_NODISCARD_EXT
1402+
# endif
1403+
1404+
# if _LIBCPP_STD_VER >= 20 || !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
1405+
# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD
1406+
# else
1407+
# define _LIBCPP_NODISCARD_AFTER_CXX17
1408+
# endif
1409+
1410+
# if __has_attribute(__no_destroy__)
1411+
# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
1412+
# else
1413+
# define _LIBCPP_NO_DESTROY
1414+
# endif
1415+
1416+
# if __has_attribute(__diagnose_if__) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
1417+
# define _LIBCPP_DIAGNOSE_WARNING(...) __attribute__((__diagnose_if__(__VA_ARGS__, "warning")))
1418+
# else
1419+
# define _LIBCPP_DIAGNOSE_WARNING(...)
1420+
# endif
1421+
1422+
// Use a function like macro to imply that it must be followed by a semicolon
1423+
# if __has_cpp_attribute(fallthrough)
1424+
# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1425+
# elif __has_attribute(__fallthrough__)
1426+
# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1427+
# else
1428+
# define _LIBCPP_FALLTHROUGH() ((void)0)
1429+
# endif
1430+
1431+
# if __has_cpp_attribute(_Clang::__lifetimebound__)
1432+
# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
1433+
# else
1434+
# define _LIBCPP_LIFETIMEBOUND
1435+
# endif
1436+
1437+
# if __has_attribute(__nodebug__)
1438+
# define _LIBCPP_NODEBUG __attribute__((__nodebug__))
1439+
# else
1440+
# define _LIBCPP_NODEBUG
1441+
# endif
1442+
1443+
# if __has_attribute(__standalone_debug__)
1444+
# define _LIBCPP_STANDALONE_DEBUG __attribute__((__standalone_debug__))
1445+
# else
1446+
# define _LIBCPP_STANDALONE_DEBUG
1447+
# endif
1448+
1449+
# if __has_attribute(__preferred_name__)
1450+
# define _LIBCPP_PREFERRED_NAME(x) __attribute__((__preferred_name__(x)))
1451+
# else
1452+
# define _LIBCPP_PREFERRED_NAME(x)
1453+
# endif
1454+
1455+
# if __has_attribute(__no_sanitize__)
1456+
# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1457+
# else
1458+
# define _LIBCPP_NO_SANITIZE(...)
1459+
# endif
1460+
1461+
# if __has_attribute(__init_priority__)
1462+
# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1463+
# else
1464+
# define _LIBCPP_INIT_PRIORITY_MAX
1465+
# endif
1466+
1467+
# if __has_attribute(__format__)
1468+
// The attribute uses 1-based indices for ordinary and static member functions.
1469+
// The attribute uses 2-based indices for non-static member functions.
1470+
# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1471+
__attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1472+
# else
1473+
# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1474+
# endif
1475+
1476+
# if __has_attribute(__packed__)
1477+
# define _LIBCPP_PACKED __attribute__((__packed__))
1478+
# else
1479+
# define _LIBCPP_PACKED
1480+
# endif
1481+
1482+
# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
1483+
# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
1484+
# else
1485+
# define _LIBCPP_DECLSPEC_EMPTY_BASES
1486+
# endif
1487+
1488+
// Allow for build-time disabling of unsigned integer sanitization
1489+
# if __has_attribute(no_sanitize) && !defined(_LIBCPP_COMPILER_GCC)
1490+
# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
1491+
# else
1492+
# define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
1493+
# endif
1494+
14891495
#endif // __cplusplus
14901496

14911497
#endif // _LIBCPP___CONFIG

0 commit comments

Comments
 (0)