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___ASSERT 11#define _LIBCPP___ASSERT 12 13#include <__config> 14#include <__verbose_abort> 15 16#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 17# pragma GCC system_header 18#endif 19 20// Automatically enable assertions when the debug mode is enabled. 21#if defined(_LIBCPP_ENABLE_DEBUG_MODE) 22# ifndef _LIBCPP_ENABLE_ASSERTIONS 23# define _LIBCPP_ENABLE_ASSERTIONS 1 24# endif 25#endif 26 27#ifndef _LIBCPP_ENABLE_ASSERTIONS 28# define _LIBCPP_ENABLE_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS_DEFAULT 29#endif 30 31#if _LIBCPP_ENABLE_ASSERTIONS != 0 && _LIBCPP_ENABLE_ASSERTIONS != 1 32# error "_LIBCPP_ENABLE_ASSERTIONS must be set to 0 or 1" 33#endif 34 35#if _LIBCPP_ENABLE_ASSERTIONS 36# define _LIBCPP_ASSERT(expression, message) \ 37 (__builtin_expect(static_cast<bool>(expression), 1) \ 38 ? (void)0 \ 39 : _LIBCPP_VERBOSE_ABORT( \ 40 "%s:%d: assertion %s failed: %s", __builtin_FILE(), __builtin_LINE(), #expression, message)) 41#elif !defined(_LIBCPP_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume) 42# define _LIBCPP_ASSERT(expression, message) \ 43 (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \ 44 __builtin_assume(static_cast<bool>(expression)) _LIBCPP_DIAGNOSTIC_POP) 45#else 46# define _LIBCPP_ASSERT(expression, message) ((void)0) 47#endif 48 49#endif // _LIBCPP___ASSERT 50