Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--- NarrowingConversionsCheck.h - clang-tidy----------------*- 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_NARROWING_CONVERSIONS_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWING_CONVERSIONS_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 
0014 namespace clang::tidy::bugprone {
0015 
0016 /// Checks for narrowing conversions, e.g:
0017 ///   int i = 0;
0018 ///   i += 0.1;
0019 ///
0020 /// For the user-facing documentation see:
0021 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/narrowing-conversions.html
0022 class NarrowingConversionsCheck : public ClangTidyCheck {
0023 public:
0024   NarrowingConversionsCheck(StringRef Name, ClangTidyContext *Context);
0025 
0026   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0027 
0028   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0029   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0030 
0031 private:
0032   void diagNarrowType(SourceLocation SourceLoc, const Expr &Lhs,
0033                       const Expr &Rhs);
0034 
0035   void diagNarrowTypeToSignedInt(SourceLocation SourceLoc, const Expr &Lhs,
0036                                  const Expr &Rhs);
0037 
0038   void diagNarrowIntegerConstant(SourceLocation SourceLoc, const Expr &Lhs,
0039                                  const Expr &Rhs, const llvm::APSInt &Value);
0040 
0041   void diagNarrowIntegerConstantToSignedInt(SourceLocation SourceLoc,
0042                                             const Expr &Lhs, const Expr &Rhs,
0043                                             const llvm::APSInt &Value,
0044                                             const uint64_t HexBits);
0045 
0046   void diagNarrowConstant(SourceLocation SourceLoc, const Expr &Lhs,
0047                           const Expr &Rhs);
0048 
0049   void diagConstantCast(SourceLocation SourceLoc, const Expr &Lhs,
0050                         const Expr &Rhs);
0051 
0052   void diagNarrowTypeOrConstant(const ASTContext &Context,
0053                                 SourceLocation SourceLoc, const Expr &Lhs,
0054                                 const Expr &Rhs);
0055 
0056   void handleIntegralCast(const ASTContext &Context, SourceLocation SourceLoc,
0057                           const Expr &Lhs, const Expr &Rhs);
0058 
0059   void handleIntegralToBoolean(const ASTContext &Context,
0060                                SourceLocation SourceLoc, const Expr &Lhs,
0061                                const Expr &Rhs);
0062 
0063   void handleIntegralToFloating(const ASTContext &Context,
0064                                 SourceLocation SourceLoc, const Expr &Lhs,
0065                                 const Expr &Rhs);
0066 
0067   void handleFloatingToIntegral(const ASTContext &Context,
0068                                 SourceLocation SourceLoc, const Expr &Lhs,
0069                                 const Expr &Rhs);
0070 
0071   void handleFloatingToBoolean(const ASTContext &Context,
0072                                SourceLocation SourceLoc, const Expr &Lhs,
0073                                const Expr &Rhs);
0074 
0075   void handleBooleanToSignedIntegral(const ASTContext &Context,
0076                                      SourceLocation SourceLoc, const Expr &Lhs,
0077                                      const Expr &Rhs);
0078 
0079   void handleFloatingCast(const ASTContext &Context, SourceLocation SourceLoc,
0080                           const Expr &Lhs, const Expr &Rhs);
0081 
0082   void handleBinaryOperator(const ASTContext &Context, SourceLocation SourceLoc,
0083                             const Expr &Lhs, const Expr &Rhs);
0084 
0085   bool handleConditionalOperator(const ASTContext &Context, const Expr &Lhs,
0086                                  const Expr &Rhs);
0087 
0088   void handleImplicitCast(const ASTContext &Context,
0089                           const ImplicitCastExpr &Cast);
0090 
0091   void handleBinaryOperator(const ASTContext &Context,
0092                             const BinaryOperator &Op);
0093 
0094   bool isWarningInhibitedByEquivalentSize(const ASTContext &Context,
0095                                           const BuiltinType &FromType,
0096                                           const BuiltinType &ToType) const;
0097 
0098   const bool WarnOnIntegerNarrowingConversion;
0099   const bool WarnOnIntegerToFloatingPointNarrowingConversion;
0100   const bool WarnOnFloatingPointNarrowingConversion;
0101   const bool WarnWithinTemplateInstantiation;
0102   const bool WarnOnEquivalentBitWidth;
0103   const StringRef IgnoreConversionFromTypes;
0104   const bool PedanticMode;
0105 };
0106 
0107 } // namespace clang::tidy::bugprone
0108 
0109 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWING_CONVERSIONS_H