StaticAnalysisFunctions.h 1.3 KB

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