assert.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // assert.h //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // Defines custom assert macro for clang/llvm. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #undef assert
  13. #undef wassert
  14. // This assert will raise a structured exception (RaiseException), using
  15. // STATUS_LLVM_ASSERT. llvm_unreachable and report_fatal_error will also
  16. // raise structured exceptions. Each indicate a condition from which the
  17. // application should not continue, but can be useful for catching and logging
  18. // during automated testing.
  19. #define STATUS_LLVM_ASSERT 0xE0000001
  20. #define STATUS_LLVM_UNREACHABLE 0xE0000002
  21. #define STATUS_LLVM_FATAL 0xE0000003
  22. #ifdef NDEBUG
  23. #define assert(_Expression) ((void)0)
  24. #else /* NDEBUG */
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. void llvm_assert(const char *_Message,
  29. const char *_File,
  30. unsigned _Line,
  31. const char *_Function);
  32. #ifdef __cplusplus
  33. }
  34. #endif
  35. #define assert(_Expression) ((void)( (!!(_Expression)) || (llvm_assert(#_Expression, __FILE__, __LINE__, __FUNCTION__), 0) ))
  36. #endif /* NDEBUG */