assert.h 917 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <sys/cdefs.h>
  8. __BEGIN_DECLS
  9. #ifdef DEBUG
  10. __attribute__((noreturn)) void __assertion_failed(const char* msg);
  11. # define __stringify_helper(x) # x
  12. # define __stringify(x) __stringify_helper(x)
  13. # define assert(expr) \
  14. do { \
  15. if (__builtin_expect(!(expr), 0)) \
  16. __assertion_failed(#expr "\n" __FILE__ ":" __stringify(__LINE__)); \
  17. } while (0)
  18. #else
  19. # define assert(expr) ((void)(0))
  20. # define VERIFY_NOT_REACHED() _abort()
  21. #endif
  22. __attribute__((noreturn)) void _abort();
  23. #ifndef __cplusplus
  24. # define static_assert _Static_assert
  25. #endif
  26. __END_DECLS