ImplicitWideningOfMultiplicationResultCheck.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //===--- ImplicitWideningOfMultiplicationResultCheck.h ----------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. #include "../utils/IncludeInserter.h"
  12. #include <optional>
  13. namespace clang::tidy::bugprone {
  14. /// Diagnoses instances of an implicit widening of multiplication result.
  15. ///
  16. /// For the user-facing documentation see:
  17. /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.html
  18. class ImplicitWideningOfMultiplicationResultCheck : public ClangTidyCheck {
  19. const ast_matchers::MatchFinder::MatchResult *Result;
  20. bool ShouldUseCXXStaticCast;
  21. bool ShouldUseCXXHeader;
  22. std::optional<FixItHint> includeStddefHeader(SourceLocation File);
  23. void handleImplicitCastExpr(const ImplicitCastExpr *ICE);
  24. void handlePointerOffsetting(const Expr *E);
  25. public:
  26. ImplicitWideningOfMultiplicationResultCheck(StringRef Name,
  27. ClangTidyContext *Context);
  28. void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
  29. Preprocessor *ModuleExpanderPP) override;
  30. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  31. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  32. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  33. private:
  34. const bool UseCXXStaticCastsInCppSources;
  35. const bool UseCXXHeadersInCppSources;
  36. utils::IncludeInserter IncludeInserter;
  37. };
  38. } // namespace clang::tidy::bugprone
  39. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H