181ad6265SDimitry Andric// -*- C++ -*- 281ad6265SDimitry Andric//===----------------------------------------------------------------------===// 381ad6265SDimitry Andric// 481ad6265SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 581ad6265SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 681ad6265SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 781ad6265SDimitry Andric// 881ad6265SDimitry Andric//===----------------------------------------------------------------------===// 981ad6265SDimitry Andric 1081ad6265SDimitry Andric#ifndef _LIBCPP___ASSERT 1181ad6265SDimitry Andric#define _LIBCPP___ASSERT 1281ad6265SDimitry Andric 13*a58f00eaSDimitry Andric#include <__assertion_handler> // Note: this include is generated by CMake and is potentially vendor-provided. 1481ad6265SDimitry Andric#include <__config> 1581ad6265SDimitry Andric 1681ad6265SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 1781ad6265SDimitry Andric# pragma GCC system_header 1881ad6265SDimitry Andric#endif 1981ad6265SDimitry Andric 2081ad6265SDimitry Andric#define _LIBCPP_ASSERT(expression, message) \ 21fe013be4SDimitry Andric (__builtin_expect(static_cast<bool>(expression), 1) \ 22fe013be4SDimitry Andric ? (void)0 \ 23*a58f00eaSDimitry Andric : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(__LINE__) ": assertion " _LIBCPP_TOSTRING( \ 24*a58f00eaSDimitry Andric expression) " failed: " message "\n")) 25fe013be4SDimitry Andric 26fe013be4SDimitry Andric// TODO: __builtin_assume can currently inhibit optimizations. Until this has been fixed and we can add 27fe013be4SDimitry Andric// assumptions without a clear optimization intent, disable that to avoid worsening the code generation. 28fe013be4SDimitry Andric// See https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609 for a discussion. 29fe013be4SDimitry Andric#if 0 && __has_builtin(__builtin_assume) 30fe013be4SDimitry Andric# define _LIBCPP_ASSUME(expression) \ 31fe013be4SDimitry Andric (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wassume") \ 32fe013be4SDimitry Andric __builtin_assume(static_cast<bool>(expression)) _LIBCPP_DIAGNOSTIC_POP) 3381ad6265SDimitry Andric#else 34fe013be4SDimitry Andric# define _LIBCPP_ASSUME(expression) ((void)0) 3581ad6265SDimitry Andric#endif 3681ad6265SDimitry Andric 3781ad6265SDimitry Andric#endif // _LIBCPP___ASSERT 38