StaticAnalysisFunctions.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set ts=8 sts=2 et sw=2 tw=80: */
  3. /* This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. #ifndef mozilla_StaticAnalysisFunctions_h
  7. #define mozilla_StaticAnalysisFunctions_h
  8. #ifndef __cplusplus
  9. #ifndef bool
  10. #include <stdbool.h>
  11. #endif
  12. #endif
  13. /*
  14. * Functions that are used as markers in Gecko code for static analysis. Their
  15. * purpose is to have different AST nodes generated during compile time and to
  16. * match them based on different checkers implemented in build/clang-plugin
  17. */
  18. #ifdef MOZ_CLANG_PLUGIN
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /*
  23. * MOZ_AssertAssignmentTest - used in MOZ_ASSERT in order to test the possible
  24. * presence of assignment instead of logical comparisons.
  25. *
  26. * Example:
  27. * MOZ_ASSERT(retVal = true);
  28. */
  29. static MOZ_ALWAYS_INLINE bool MOZ_AssertAssignmentTest(bool exprResult) {
  30. return exprResult;
  31. }
  32. #ifdef __cplusplus
  33. }
  34. #endif /* __cplusplus */
  35. #define MOZ_CHECK_ASSERT_ASSIGNMENT(expr) MOZ_AssertAssignmentTest(!!(expr))
  36. #else
  37. #define MOZ_CHECK_ASSERT_ASSIGNMENT(expr) (!!(expr))
  38. #endif /* MOZ_CLANG_PLUGIN */
  39. #endif /* StaticAnalysisFunctions_h */