StaticAnalysisFunctions.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /**
  21. * MOZ_KnownLive - used to opt an argument out of the CanRunScript checker so
  22. * that we don't check it if is a strong ref.
  23. *
  24. * Example:
  25. * canRunScript(MOZ_KnownLive(rawPointer));
  26. */
  27. template <typename T>
  28. static MOZ_ALWAYS_INLINE T* MOZ_KnownLive(T* ptr) { return ptr; }
  29. extern "C" {
  30. #endif
  31. /**
  32. * MOZ_AssertAssignmentTest - used in MOZ_ASSERT in order to test the possible
  33. * presence of assignment instead of logical comparisons.
  34. *
  35. * Example:
  36. * MOZ_ASSERT(retVal = true);
  37. */
  38. static MOZ_ALWAYS_INLINE bool MOZ_AssertAssignmentTest(bool exprResult) {
  39. return exprResult;
  40. }
  41. #ifdef __cplusplus
  42. }
  43. #endif /* __cplusplus */
  44. #define MOZ_CHECK_ASSERT_ASSIGNMENT(expr) MOZ_AssertAssignmentTest(!!(expr))
  45. #else
  46. #define MOZ_CHECK_ASSERT_ASSIGNMENT(expr) (!!(expr))
  47. #endif /* MOZ_CLANG_PLUGIN */
  48. #endif /* StaticAnalysisFunctions_h */