Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:18

0001 //===--- ImplicitWideningOfMultiplicationResultCheck.h ----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "../utils/IncludeInserter.h"
0014 #include <optional>
0015 
0016 namespace clang::tidy::bugprone {
0017 
0018 /// Diagnoses instances of an implicit widening of multiplication result.
0019 ///
0020 /// For the user-facing documentation see:
0021 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/implicit-widening-of-multiplication-result.html
0022 class ImplicitWideningOfMultiplicationResultCheck : public ClangTidyCheck {
0023   const ast_matchers::MatchFinder::MatchResult *Result;
0024   bool ShouldUseCXXStaticCast;
0025   bool ShouldUseCXXHeader;
0026 
0027   std::optional<FixItHint> includeStddefHeader(SourceLocation File);
0028 
0029   void handleImplicitCastExpr(const ImplicitCastExpr *ICE);
0030   void handlePointerOffsetting(const Expr *E);
0031 
0032 public:
0033   ImplicitWideningOfMultiplicationResultCheck(StringRef Name,
0034                                               ClangTidyContext *Context);
0035   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
0036                            Preprocessor *ModuleExpanderPP) override;
0037   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0038   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0039   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0040 
0041 private:
0042   const bool UseCXXStaticCastsInCppSources;
0043   const bool UseCXXHeadersInCppSources;
0044   const bool IgnoreConstantIntExpr;
0045   utils::IncludeInserter IncludeInserter;
0046 };
0047 
0048 } // namespace clang::tidy::bugprone
0049 
0050 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_IMPLICITWIDENINGOFMULTIPLICATIONRESULTCHECK_H