diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -51,10 +51,6 @@ include(HandleCompilerRT) # Basic options --------------------------------------------------------------- -option(LIBCXX_ENABLE_ASSERTIONS - "Enable assertions inside the compiled library, and at the same time make it the - default when compiling user code. Note that assertions can be enabled or disabled - by users in their own code regardless of this option." OFF) option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) option(LIBCXX_ENABLE_STATIC "Build libc++ as a static library." ON) option(LIBCXX_ENABLE_FILESYSTEM @@ -72,6 +68,10 @@ message(FATAL_ERROR "Unsupported hardening mode: '${LIBCXX_HARDENING_MODE}'. Supported values are ${LIBCXX_SUPPORTED_HARDENING_MODES}.") endif() +option(LIBCXX_ENABLE_ASSERTIONS + "This is a deprecated option that is only provided for backward compatibility. + Enabling this option is equivalent to setting LIBCXX_HARDENING_MODE to + "hardened"." OFF) option(LIBCXX_ENABLE_RANDOM_DEVICE "Whether to include support for std::random_device in the library. Disabling this can be useful when building the library for platforms that don't have @@ -600,7 +600,7 @@ # Assertion flags ============================================================= define_if(LIBCXX_DEBUG_BUILD -D_DEBUG) -if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD) +if (NOT LIBCXX_HARDENING_MODE STREQUAL "unchecked" AND NOT LIBCXX_DEBUG_BUILD) # MSVC doesn't like _DEBUG on release builds. See PR 4379. define_if_not(LIBCXX_TARGETING_MSVC -D_DEBUG) endif() diff --git a/libcxx/cmake/caches/Generic-assertions.cmake b/libcxx/cmake/caches/Generic-assertions.cmake deleted file mode 100644 --- a/libcxx/cmake/caches/Generic-assertions.cmake +++ /dev/null @@ -1,2 +0,0 @@ -set(LIBCXX_ENABLE_ASSERTIONS ON CACHE BOOL "") -set(LIBCXXABI_ENABLE_ASSERTIONS ON CACHE BOOL "") diff --git a/libcxx/docs/BuildingLibcxx.rst b/libcxx/docs/BuildingLibcxx.rst --- a/libcxx/docs/BuildingLibcxx.rst +++ b/libcxx/docs/BuildingLibcxx.rst @@ -211,15 +211,6 @@ Toggle the installation of the libc++ headers. -.. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL - - **Default**: ``OFF`` - - Build libc++ with assertions enabled in the compiled library, and enable assertions - by default when building user code as well. Assertions can be turned off by users - by defining ``_LIBCPP_ENABLE_ASSERTIONS=0``. For details, see - :ref:`the documentation `. - .. option:: LIBCXX_ENABLE_SHARED:BOOL **Default**: ``ON`` diff --git a/libcxx/include/__assert b/libcxx/include/__assert --- a/libcxx/include/__assert +++ b/libcxx/include/__assert @@ -17,15 +17,7 @@ # pragma GCC system_header #endif -#ifndef _LIBCPP_ENABLE_ASSERTIONS -# define _LIBCPP_ENABLE_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS_DEFAULT -#endif - -#if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 -# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" -#endif - -#if _LIBCPP_ENABLE_ASSERTIONS +#if _LIBCPP_ENABLE_HARDENED_MODE || _LIBCPP_ENABLE_DEBUG_MODE # define _LIBCPP_ASSERT(expression, message) \ (__builtin_expect(static_cast(expression), 1) \ ? (void)0 \ @@ -42,6 +34,7 @@ # define _LIBCPP_ASSERT(expression, message) ((void)0) #endif +// TODO(hardening): only enable uncategorized assertions in the debug mode. #define _LIBCPP_ASSERT_UNCATEGORIZED(expression, message) _LIBCPP_ASSERT(expression, message) #endif // _LIBCPP___ASSERT diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -208,6 +208,21 @@ // HARDENING { +// This is for backward compatibility -- make enabling `_LIBCPP_ENABLE_ASSERTIONS` (which predates hardening modes) +// equivalent to setting the hardened mode. +# ifdef(_LIBCPP_ENABLE_ASSERTIONS) +# warning "_LIBCPP_ENABLE_ASSERTIONS is deprecated, please use _LIBCPP_ENABLE_HARDENED_MODE instead." +# endif +# ifndef _LIBCPP_ENABLE_ASSERTIONS +# define _LIBCPP_ENABLE_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS_DEFAULT +# endif +# if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 +# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" +# endif +# if _LIBCPP_ENABLE_ASSERTIONS +# define _LIBCPP_ENABLE_HARDENED_MODE 1 +# endif + // Enables the hardened mode which consists of all checks intended to be used in production. Hardened mode prioritizes // security-critical checks that can be done with relatively little overhead in constant time. Mutually exclusive with // `_LIBCPP_ENABLE_DEBUG_MODE`. @@ -245,21 +260,11 @@ // Hardened mode checks. # if _LIBCPP_ENABLE_HARDENED_MODE -// Automatically enable assertions in hardened mode (unless the user explicitly turned them off). -# ifndef _LIBCPP_ENABLE_ASSERTIONS -# define _LIBCPP_ENABLE_ASSERTIONS 1 -# endif - // TODO(hardening): more checks to be added here... // Debug mode checks. # elif _LIBCPP_ENABLE_DEBUG_MODE -// Automatically enable assertions in debug mode (unless the user explicitly turned them off). -# ifndef _LIBCPP_ENABLE_ASSERTIONS -# define _LIBCPP_ENABLE_ASSERTIONS 1 -# endif - // TODO(hardening): more checks to be added here... // Disable all checks if neither the hardened mode nor the debug mode is enabled. diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot --- a/libcxx/utils/ci/run-buildbot +++ b/libcxx/utils/ci/run-buildbot @@ -381,12 +381,6 @@ -DLIBUNWIND_TEST_CONFIG="llvm-libunwind-merged.cfg.in" check-runtimes ;; -generic-assertions) - clean - generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-assertions.cmake" - check-runtimes - check-abi-list -;; generic-hardened-mode) clean generate-cmake -C "${MONOREPO_ROOT}/libcxx/cmake/caches/Generic-hardened-mode.cmake" diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py --- a/libcxx/utils/libcxx/test/params.py +++ b/libcxx/utils/libcxx/test/params.py @@ -282,18 +282,6 @@ help="Whether to enable tests that take longer to run. This can be useful when running on a very slow device.", actions=lambda enabled: [] if not enabled else [AddFeature("long_tests")], ), - Parameter( - name="enable_assertions", - choices=[True, False], - type=bool, - default=False, - help="Whether to enable assertions when compiling the test suite. This is only meaningful when " - "running the tests against libc++.", - actions=lambda assertions: [] if not assertions else [ - AddCompileFlag("-D_LIBCPP_ENABLE_ASSERTIONS=1"), - AddFeature("libcpp-has-assertions"), - ], - ), Parameter( name="hardening_mode", choices=["unchecked", "hardened", "debug"],