77// ===----------------------------------------------------------------------===//
88
99#ifndef _LIBCPP___CONFIGURATION_HARDENING_H
10- # define _LIBCPP___CONFIGURATION_HARDENING_H
10+ #define _LIBCPP___CONFIGURATION_HARDENING_H
1111
12- # include < __config_site>
13- # include < __configuration/experimental.h>
14- # include < __configuration/language.h>
12+ #include < __config_site>
13+ #include < __configuration/experimental.h>
14+ #include < __configuration/language.h>
1515
16- # ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
17- # pragma GCC system_header
18- # endif
16+ #ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
17+ # pragma GCC system_header
18+ #endif
1919
2020// TODO(LLVM 23): Remove this. We're making these an error to catch folks who might not have migrated.
2121// Since hardening went through several changes (many of which impacted user-facing macros),
2222// we're keeping these checks around for a bit longer than usual. Failure to properly configure
2323// hardening results in checks being dropped silently, which is a pretty big deal.
24- # if defined(_LIBCPP_ENABLE_ASSERTIONS)
25- # error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
26- # endif
27- # if defined(_LIBCPP_ENABLE_HARDENED_MODE)
28- # error "_LIBCPP_ENABLE_HARDENED_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
29- # endif
30- # if defined(_LIBCPP_ENABLE_SAFE_MODE)
31- # error "_LIBCPP_ENABLE_SAFE_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
32- # endif
33- # if defined(_LIBCPP_ENABLE_DEBUG_MODE)
34- # error "_LIBCPP_ENABLE_DEBUG_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
35- # endif
24+ #if defined(_LIBCPP_ENABLE_ASSERTIONS)
25+ # error "_LIBCPP_ENABLE_ASSERTIONS has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
26+ #endif
27+ #if defined(_LIBCPP_ENABLE_HARDENED_MODE)
28+ # error "_LIBCPP_ENABLE_HARDENED_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
29+ #endif
30+ #if defined(_LIBCPP_ENABLE_SAFE_MODE)
31+ # error "_LIBCPP_ENABLE_SAFE_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
32+ #endif
33+ #if defined(_LIBCPP_ENABLE_DEBUG_MODE)
34+ # error "_LIBCPP_ENABLE_DEBUG_MODE has been removed, please use _LIBCPP_HARDENING_MODE=<mode> instead (see docs)"
35+ #endif
3636
3737// The library provides the macro `_LIBCPP_HARDENING_MODE` which can be set to one of the following values:
3838//
115115# define _LIBCPP_HARDENING_MODE_DEBUG (1 << 3 )
116116// clang-format on
117117
118- # ifndef _LIBCPP_HARDENING_MODE
118+ #ifndef _LIBCPP_HARDENING_MODE
119119
120- # ifndef _LIBCPP_HARDENING_MODE_DEFAULT
121- # error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \
120+ # ifndef _LIBCPP_HARDENING_MODE_DEFAULT
121+ # error _LIBCPP_HARDENING_MODE_DEFAULT is not defined. This definition should be set at configuration time in the \
122122`__config_site` header, please make sure your installation of libc++ is not broken.
123- # endif
124-
125- # define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
126123# endif
127124
128- # if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && \
129- _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \
130- _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \
131- _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
132- # error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
125+ # define _LIBCPP_HARDENING_MODE _LIBCPP_HARDENING_MODE_DEFAULT
126+ #endif
127+
128+ #if _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_NONE && _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_FAST && \
129+ _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \
130+ _LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
131+ # error _LIBCPP_HARDENING_MODE must be set to one of the following values: \
133132_LIBCPP_HARDENING_MODE_NONE, \
134133_LIBCPP_HARDENING_MODE_FAST, \
135134_LIBCPP_HARDENING_MODE_EXTENSIVE, \
136135_LIBCPP_HARDENING_MODE_DEBUG
137- # endif
136+ #endif
138137
139138// Hardening assertion semantics generally mirror the evaluation semantics of C++26 Contracts:
140139// - `ignore` evaluates the assertion but doesn't do anything if it fails (note that it differs from the Contracts
@@ -159,45 +158,45 @@ _LIBCPP_HARDENING_MODE_DEBUG
159158
160159// If the user or the vendor attempt to configure the assertion semantic, check that it is allowed in the current
161160// environment.
162- # if defined(_LIBCPP_ASSERTION_SEMANTIC) || defined(_LIBCPP_ASSERTION_SEMANTIC_DEFAULT)
163- # if !_LIBCPP_HAS_EXPERIMENTAL_LIBRARY
164- # error "Assertion semantics are an experimental feature."
165- # endif
166- # if defined(_LIBCPP_CXX03_LANG)
167- # error "Assertion semantics are not available in the C++03 mode."
168- # endif
169- # endif // defined(_LIBCPP_ASSERTION_SEMANTIC) || defined(_LIBCPP_ASSERTION_SEMANTIC_DEFAULT)
161+ #if defined(_LIBCPP_ASSERTION_SEMANTIC) || defined(_LIBCPP_ASSERTION_SEMANTIC_DEFAULT)
162+ # if !_LIBCPP_HAS_EXPERIMENTAL_LIBRARY
163+ # error "Assertion semantics are an experimental feature."
164+ # endif
165+ # if defined(_LIBCPP_CXX03_LANG)
166+ # error "Assertion semantics are not available in the C++03 mode."
167+ # endif
168+ #endif // defined(_LIBCPP_ASSERTION_SEMANTIC) || defined(_LIBCPP_ASSERTION_SEMANTIC_DEFAULT)
170169
171170// There are 2 ways to configure the assertion semantic, listed in order of precedence:
172171// 1. The `_LIBCPP_ASSERTION_SEMANTIC` macro, defined directly by the user.
173172// 2. The `LIBCXX_ASSERTION_SEMANTIC` CMake variable, set by the vendor.
174173// If neither `_LIBCPP_ASSERTION_SEMANTIC` nor `LIBCXX_ASSERTION_SEMANTIC` are defined, the default mapping is used
175174// which determines the semantic based on the hardening mode in effect: production-capable modes map to `quick-enforce`
176175// (i.e., trap) and the `debug` mode maps to `enforce` (i.e., log and abort).
177- # ifndef _LIBCPP_ASSERTION_SEMANTIC // User-provided semantic takes top priority -- don't override if set.
178-
179- # ifdef _LIBCPP_ASSERTION_SEMANTIC_DEFAULT // Vendor-provided semantic takes second priority.
180- # define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_DEFAULT
181- # else // Fallback: use the default mapping.
182- # if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
183- # define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_ENFORCE
184- # else
185- # define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE
186- # endif
187- #endif // ifdef _LIBCPP_ASSERTION_SEMANTIC_DEFAULT
176+ #ifndef _LIBCPP_ASSERTION_SEMANTIC // User-provided semantic takes top priority -- don't override if set.
177+
178+ # ifdef _LIBCPP_ASSERTION_SEMANTIC_DEFAULT // Vendor-provided semantic takes second priority.
179+ # define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_DEFAULT
180+ # else // Fallback: use the default mapping.
181+ # if _LIBCPP_HARDENING_MODE == _LIBCPP_HARDENING_MODE_DEBUG
182+ # define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_ENFORCE
183+ # else
184+ # define _LIBCPP_ASSERTION_SEMANTIC _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE
185+ # endif
186+ # endif // ifdef _LIBCPP_ASSERTION_SEMANTIC_DEFAULT
188187
189- # endif // _LIBCPP_ASSERTION_SEMANTIC
188+ #endif // _LIBCPP_ASSERTION_SEMANTIC
190189
191190// Finally, validate the selected semantic (in case the user tries setting it to an incorrect value):
192- # if _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_IGNORE && \
193- _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_OBSERVE && \
194- _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE && \
195- _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_ENFORCE
196- # error _LIBCPP_ASSERTION_SEMANTIC must be set to one of the following values: \
191+ #if _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_IGNORE && \
192+ _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_OBSERVE && \
193+ _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE && \
194+ _LIBCPP_ASSERTION_SEMANTIC != _LIBCPP_ASSERTION_SEMANTIC_ENFORCE
195+ # error _LIBCPP_ASSERTION_SEMANTIC must be set to one of the following values: \
197196_LIBCPP_ASSERTION_SEMANTIC_IGNORE, \
198197_LIBCPP_ASSERTION_SEMANTIC_OBSERVE, \
199198_LIBCPP_ASSERTION_SEMANTIC_QUICK_ENFORCE, \
200199_LIBCPP_ASSERTION_SEMANTIC_ENFORCE
201- # endif
200+ #endif
202201
203- # endif // _LIBCPP___CONFIGURATION_HARDENING_H
202+ #endif // _LIBCPP___CONFIGURATION_HARDENING_H
0 commit comments