codekingpro/portable-devtools
114k
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-exception7// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.8//9//===----------------------------------------------------------------------===//10 11#ifndef _LIBCUDACXX___ASSERT12#define _LIBCUDACXX___ASSERT13 14#ifndef __cuda_std__15#include <__config>16#endif // __cuda_std__17 18#include "__verbose_abort"19 20#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)21# pragma GCC system_header22#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)23# pragma clang system_header24#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)25# pragma system_header26#endif // no system header27 28// This is for backwards compatibility with code that might have been enabling29// assertions through the Debug mode previously.30// TODO: In LLVM 16, make it an error to define _LIBCUDACXX_DEBUG31#if defined(_LIBCUDACXX_DEBUG)32# ifndef _LIBCUDACXX_ENABLE_ASSERTIONS33# define _LIBCUDACXX_ENABLE_ASSERTIONS 134# endif35#endif36 37// Automatically enable assertions when the debug mode is enabled.38#if defined(_LIBCUDACXX_ENABLE_DEBUG_MODE)39# ifndef _LIBCUDACXX_ENABLE_ASSERTIONS40# define _LIBCUDACXX_ENABLE_ASSERTIONS 141# endif42#endif43 44#ifndef _LIBCUDACXX_ENABLE_ASSERTIONS45# define _LIBCUDACXX_ENABLE_ASSERTIONS _LIBCUDACXX_ENABLE_ASSERTIONS_DEFAULT46#endif47 48#if _LIBCUDACXX_ENABLE_ASSERTIONS != 0 && _LIBCUDACXX_ENABLE_ASSERTIONS != 149# error "_LIBCUDACXX_ENABLE_ASSERTIONS must be set to 0 or 1"50#endif51 52#if _LIBCUDACXX_ENABLE_ASSERTIONS53# define _LIBCUDACXX_ASSERT(expression, message) \54 (_CCCL_DIAG_PUSH \55 _CCCL_DIAG_SUPPRESS_CLANG("-Wassume") \56 __builtin_expect(static_cast<bool>(expression), 1) ? \57 (void)0 : \58 ::_CUDA_VSTD::__libcpp_verbose_abort("%s:%d: assertion %s failed: %s", __FILE__, __LINE__, #expression, message)59 _CCCL_DIAG_POP)60#elif 0 // !defined(_LIBCUDACXX_ASSERTIONS_DISABLE_ASSUME) && __has_builtin(__builtin_assume)61# define _LIBCUDACXX_ASSERT(expression, message) \62 (_CCCL_DIAG_PUSH \63 _CCCL_DIAG_SUPPRESS_CLANG("-Wassume") \64 __builtin_assume(static_cast<bool>(expression)) \65 _CCCL_DIAG_POP)66#else67# define _LIBCUDACXX_ASSERT(expression, message) ((void)0)68#endif69 70#endif // _LIBCUDACXX___ASSERT71 