[libcxx] Never use <cassert> within libc++
Summary: It is my opinion that libc++ should never use `<cassert>`, including in the `dylib`. This patch remove all uses of `assert` from within libc++ and replaces most of them with `_LIBCPP_ASSERT` instead. Additionally this patch turn `LIBCXX_ENABLE_ASSERTIONS` off by default, because the standard library should not be aborting user programs unless explicitly asked to. Reviewers: mclow.lists, compnerd, smeenai Reviewed By: mclow.lists Subscribers: mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D29063 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@292883 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -60,7 +60,7 @@ endif()
|
|||||||
include(CMakeDependentOption)
|
include(CMakeDependentOption)
|
||||||
|
|
||||||
# Basic options ---------------------------------------------------------------
|
# Basic options ---------------------------------------------------------------
|
||||||
option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
|
option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." OFF)
|
||||||
option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
|
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_STATIC "Build libc++ as a static library." ON)
|
||||||
option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON)
|
option(LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY "Build libc++experimental.a" ON)
|
||||||
@@ -501,6 +501,7 @@ endif()
|
|||||||
# Assertion flags =============================================================
|
# Assertion flags =============================================================
|
||||||
define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG)
|
define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG)
|
||||||
define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG)
|
define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG)
|
||||||
|
define_if(LIBCXX_ENABLE_ASSERTIONS -D_LIBCPP_DEBUG=0)
|
||||||
define_if(LIBCXX_DEBUG_BUILD -D_DEBUG)
|
define_if(LIBCXX_DEBUG_BUILD -D_DEBUG)
|
||||||
if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD)
|
if (LIBCXX_ENABLE_ASSERTIONS AND NOT LIBCXX_DEBUG_BUILD)
|
||||||
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
|
# MSVC doesn't like _DEBUG on release builds. See PR 4379.
|
||||||
|
|||||||
@@ -824,7 +824,9 @@ template <unsigned> struct __static_assert_check {};
|
|||||||
# else
|
# else
|
||||||
# error Supported values for _LIBCPP_DEBUG are 0 and 1
|
# error Supported values for _LIBCPP_DEBUG are 0 and 1
|
||||||
# endif
|
# endif
|
||||||
|
# if !defined(_LIBCPP_BUILDING_LIBRARY)
|
||||||
# define _LIBCPP_EXTERN_TEMPLATE(...)
|
# define _LIBCPP_EXTERN_TEMPLATE(...)
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _LIBCPP_EXTERN_TEMPLATE
|
#ifndef _LIBCPP_EXTERN_TEMPLATE
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
# include <pthread.h>
|
# include <pthread.h>
|
||||||
# include <sched.h>
|
# include <sched.h>
|
||||||
#elif defined(_LIBCPP_HAS_THREAD_API_WIN32)
|
#elif defined(_LIBCPP_HAS_THREAD_API_WIN32)
|
||||||
#include <assert.h>
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <fibersapi.h>
|
#include <fibersapi.h>
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
#include "condition_variable"
|
#include "condition_variable"
|
||||||
#include "thread"
|
#include "thread"
|
||||||
#include "system_error"
|
#include "system_error"
|
||||||
#include "cassert"
|
|
||||||
|
|
||||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,9 @@
|
|||||||
// Source Licenses. See LICENSE.TXT for details.
|
// Source Licenses. See LICENSE.TXT for details.
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
#undef NDEBUG
|
|
||||||
#include "experimental/filesystem"
|
#include "experimental/filesystem"
|
||||||
#include "string_view"
|
#include "string_view"
|
||||||
#include "utility"
|
#include "utility"
|
||||||
#include "cassert"
|
|
||||||
|
|
||||||
namespace { namespace parser
|
namespace { namespace parser
|
||||||
{
|
{
|
||||||
@@ -113,7 +111,6 @@ public:
|
|||||||
void decrement() noexcept {
|
void decrement() noexcept {
|
||||||
const PosPtr REnd = &Path.front() - 1;
|
const PosPtr REnd = &Path.front() - 1;
|
||||||
const PosPtr RStart = getCurrentTokenStartPos() - 1;
|
const PosPtr RStart = getCurrentTokenStartPos() - 1;
|
||||||
assert(RStart != REnd);
|
|
||||||
|
|
||||||
switch (State) {
|
switch (State) {
|
||||||
case PS_AtEnd: {
|
case PS_AtEnd: {
|
||||||
@@ -322,7 +319,6 @@ string_view_t path::__root_path_raw() const
|
|||||||
auto NextCh = PP.peek();
|
auto NextCh = PP.peek();
|
||||||
if (NextCh && *NextCh == '/') {
|
if (NextCh && *NextCh == '/') {
|
||||||
++PP;
|
++PP;
|
||||||
assert(PP.State == PathParser::PS_InRootDir);
|
|
||||||
return createView(__pn_.data(), &PP.RawEntry.back());
|
return createView(__pn_.data(), &PP.RawEntry.back());
|
||||||
}
|
}
|
||||||
return PP.RawEntry;
|
return PP.RawEntry;
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include "mutex"
|
#include "mutex"
|
||||||
#include "limits"
|
#include "limits"
|
||||||
#include "system_error"
|
#include "system_error"
|
||||||
#include "cassert"
|
|
||||||
#include "include/atomic_support.h"
|
#include "include/atomic_support.h"
|
||||||
|
|
||||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||||
@@ -45,7 +44,7 @@ mutex::unlock() _NOEXCEPT
|
|||||||
{
|
{
|
||||||
int ec = __libcpp_mutex_unlock(&__m_);
|
int ec = __libcpp_mutex_unlock(&__m_);
|
||||||
(void)ec;
|
(void)ec;
|
||||||
assert(ec == 0);
|
_LIBCPP_ASSERT(ec == 0, "call to mutex::unlock failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursive_mutex
|
// recursive_mutex
|
||||||
@@ -61,7 +60,7 @@ recursive_mutex::~recursive_mutex()
|
|||||||
{
|
{
|
||||||
int e = __libcpp_recursive_mutex_destroy(&__m_);
|
int e = __libcpp_recursive_mutex_destroy(&__m_);
|
||||||
(void)e;
|
(void)e;
|
||||||
assert(e == 0);
|
_LIBCPP_ASSERT(e == 0, "call to ~recursive_mutex() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -77,7 +76,7 @@ recursive_mutex::unlock() _NOEXCEPT
|
|||||||
{
|
{
|
||||||
int e = __libcpp_recursive_mutex_unlock(&__m_);
|
int e = __libcpp_recursive_mutex_unlock(&__m_);
|
||||||
(void)e;
|
(void)e;
|
||||||
assert(e == 0);
|
_LIBCPP_ASSERT(e == 0, "call to recursive_mutex::unlock() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
#include "cstring"
|
#include "cstring"
|
||||||
#include "cstdio"
|
#include "cstdio"
|
||||||
#include "cstdlib"
|
#include "cstdlib"
|
||||||
#include "cassert"
|
|
||||||
#include "string"
|
#include "string"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
#include "__debug"
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include <android/api-level.h>
|
#include <android/api-level.h>
|
||||||
@@ -96,7 +96,7 @@ string do_strerror_r(int ev) {
|
|||||||
std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev);
|
std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev);
|
||||||
return string(buffer);
|
return string(buffer);
|
||||||
} else {
|
} else {
|
||||||
assert(new_errno == ERANGE);
|
_LIBCPP_ASSERT(new_errno == ERANGE, "unexpected error from ::strerr_r");
|
||||||
// FIXME maybe? 'strerror_buff_size' is likely to exceed the
|
// FIXME maybe? 'strerror_buff_size' is likely to exceed the
|
||||||
// maximum error size so ERANGE shouldn't be returned.
|
// maximum error size so ERANGE shouldn't be returned.
|
||||||
std::abort();
|
std::abort();
|
||||||
|
|||||||
Reference in New Issue
Block a user