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 9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H 10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H 11 12 #include "../ClangTidyCheck.h" 13 #include "../utils/IncludeInserter.h" 14 15 namespace clang { 16 namespace tidy { 17 namespace bugprone { 18 19 /// Diagnoses instances of an implicit widening of multiplication result. 20 /// 21 /// For the user-facing documentation see: 22 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.html 23 class ImplicitWideningOfMultiplicationResultCheck : public ClangTidyCheck { 24 const ast_matchers::MatchFinder::MatchResult *Result; 25 bool ShouldUseCXXStaticCast; 26 bool ShouldUseCXXHeader; 27 28 llvm::Optional<FixItHint> includeStddefHeader(SourceLocation File); 29 30 void handleImplicitCastExpr(const ImplicitCastExpr *ICE); 31 void handlePointerOffsetting(const Expr *E); 32 33 public: 34 ImplicitWideningOfMultiplicationResultCheck(StringRef Name, 35 ClangTidyContext *Context); 36 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, 37 Preprocessor *ModuleExpanderPP) override; 38 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 39 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 40 void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 41 42 private: 43 const bool UseCXXStaticCastsInCppSources; 44 const bool UseCXXHeadersInCppSources; 45 utils::IncludeInserter IncludeInserter; 46 }; 47 48 } // namespace bugprone 49 } // namespace tidy 50 } // namespace clang 51 52 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H 53