clang-tools  17.0.0git
ImplicitWideningOfMultiplicationResultCheck.h
Go to the documentation of this file.
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
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:
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  utils::IncludeInserter IncludeInserter;
45 };
46 
47 } // namespace clang::tidy::bugprone
48 
49 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: ImplicitWideningOfMultiplicationResultCheck.cpp:240
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:114
E
const Expr * E
Definition: AvoidBindCheck.cpp:86
clang::tidy::utils::IncludeInserter
Produces fixes to insert specified includes to source files, if not yet present.
Definition: IncludeInserter.h:55
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:53
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: ImplicitWideningOfMultiplicationResultCheck.cpp:256
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck
Diagnoses instances of an implicit widening of multiplication result.
Definition: ImplicitWideningOfMultiplicationResultCheck.h:22
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:68
Name
Token Name
Definition: MacroToEnumCheck.cpp:87
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:28
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: ImplicitWideningOfMultiplicationResultCheck.cpp:53
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck::ImplicitWideningOfMultiplicationResultCheck
ImplicitWideningOfMultiplicationResultCheck(StringRef Name, ClangTidyContext *Context)
Definition: ImplicitWideningOfMultiplicationResultCheck.cpp:38
clang::tidy::bugprone
Definition: ArgumentCommentCheck.cpp:19
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition: ImplicitWideningOfMultiplicationResultCheck.cpp:48