assert.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. #ifdef __cplusplus
  32. }
  33. #endif
  34. #define assert(_Expression) ((void)( (!!(_Expression)) || (llvm_assert(#_Expression, __FILE__, __LINE__), 0) ))
  35. #endif /* NDEBUG */