clang-tools  14.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 
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
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:
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
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: ImplicitWideningOfMultiplicationResultCheck.cpp:241
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
E
const Expr * E
Definition: AvoidBindCheck.cpp:88
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:54
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:257
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck
Diagnoses instances of an implicit widening of multiplication result.
Definition: ImplicitWideningOfMultiplicationResultCheck.h:23
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:71
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:29
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:54
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
SM
const SourceManager & SM
Definition: IncludeCleaner.cpp:140
clang::tidy::bugprone::ImplicitWideningOfMultiplicationResultCheck::ImplicitWideningOfMultiplicationResultCheck
ImplicitWideningOfMultiplicationResultCheck(StringRef Name, ClangTidyContext *Context)
Definition: ImplicitWideningOfMultiplicationResultCheck.cpp:39
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:49