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