https://github.com/vbvictor created https://github.com/llvm/llvm-project/pull/167040
None >From 14c7714eb44149063fdcbe488438346633446a14 Mon Sep 17 00:00:00 2001 From: Victor Baranov <[email protected]> Date: Sat, 8 Nov 2025 01:53:30 +0300 Subject: [PATCH] [clang-tidy][NFC] Fix misc-const-correctness warnings (3/N) --- .../clang-tidy/abseil/AbseilMatcher.h | 4 +-- .../abseil/DurationAdditionCheck.cpp | 2 +- .../abseil/DurationComparisonCheck.cpp | 4 +-- .../abseil/DurationConversionCastCheck.cpp | 8 ++++-- .../abseil/DurationFactoryScaleCheck.cpp | 2 +- .../clang-tidy/abseil/DurationRewriter.cpp | 4 +-- .../abseil/DurationSubtractionCheck.cpp | 2 +- .../DurationUnnecessaryConversionCheck.cpp | 6 ++-- .../abseil/FasterStrsplitDelimiterCheck.cpp | 2 +- .../abseil/NoInternalDependenciesCheck.cpp | 2 +- .../abseil/StringFindStartswithCheck.cpp | 4 +-- .../clang-tidy/abseil/TimeComparisonCheck.cpp | 4 +-- .../abseil/TimeSubtractionCheck.cpp | 8 +++--- .../UpgradeDurationConversionsCheck.cpp | 10 +++---- .../altera/IdDependentBackwardBranchCheck.cpp | 14 +++++----- .../altera/IdDependentBackwardBranchCheck.h | 4 +-- .../altera/KernelNameRestrictionCheck.cpp | 4 +-- .../altera/StructPackAlignCheck.cpp | 28 ++++++++++--------- .../clang-tidy/altera/UnrollLoopsCheck.cpp | 2 +- .../clang-tidy/android/CloexecAcceptCheck.cpp | 9 +++--- .../clang-tidy/android/CloexecCheck.cpp | 9 +++--- .../clang-tidy/android/CloexecDupCheck.cpp | 2 +- .../clang-tidy/android/CloexecOpenCheck.cpp | 2 +- .../clang-tidy/android/CloexecPipeCheck.cpp | 2 +- .../ComparisonInTempFailureRetryCheck.cpp | 2 +- .../clang-tidy/boost/UseRangesCheck.cpp | 2 +- .../clang-tidy/objc/AssertEquals.cpp | 4 +-- .../clang-tidy/objc/NSDateFormatterCheck.cpp | 2 +- .../NSInvocationArgumentLifetimeCheck.cpp | 12 ++++---- .../objc/PropertyDeclarationCheck.cpp | 11 ++++---- .../clang-tidy/objc/SuperSelfCheck.cpp | 4 +-- 31 files changed, 91 insertions(+), 84 deletions(-) diff --git a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h index ac2e759c4c270..982774ca4db5b 100644 --- a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h +++ b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h @@ -34,7 +34,7 @@ AST_POLYMORPHIC_MATCHER( isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc, NestedNameSpecifierLoc)) { auto &SourceManager = Finder->getASTContext().getSourceManager(); - SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc()); + const SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc()); if (Loc.isInvalid()) return false; OptionalFileEntryRef FileEntry = @@ -45,7 +45,7 @@ AST_POLYMORPHIC_MATCHER( // [absl-library] is AbseilLibraries list entry. StringRef Path = FileEntry->getName(); static constexpr llvm::StringLiteral AbslPrefix("absl/"); - size_t PrefixPosition = Path.find(AbslPrefix); + const size_t PrefixPosition = Path.find(AbslPrefix); if (PrefixPosition == StringRef::npos) return false; Path = Path.drop_front(PrefixPosition + AbslPrefix.size()); diff --git a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp index 03f78f1c96252..421e5973d4fe0 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp @@ -41,7 +41,7 @@ void DurationAdditionCheck::check(const MatchFinder::MatchResult &Result) { if (!Scale) return; - llvm::StringRef TimeFactory = getTimeInverseForScale(*Scale); + const llvm::StringRef TimeFactory = getTimeInverseForScale(*Scale); FixItHint Hint; if (Call == Binop->getLHS()->IgnoreParenImpCasts()) { diff --git a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp index 16a244b7e9997..f00877754f952 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp @@ -38,9 +38,9 @@ void DurationComparisonCheck::check(const MatchFinder::MatchResult &Result) { // if nothing needs to be done. if (isInMacro(Result, Binop->getLHS()) || isInMacro(Result, Binop->getRHS())) return; - std::string LhsReplacement = + const std::string LhsReplacement = rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS()); - std::string RhsReplacement = + const std::string RhsReplacement = rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS()); diag(Binop->getBeginLoc(), "perform comparison in the duration domain") diff --git a/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp index 11d6017c22e9d..ef06a9e2ba572 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp @@ -41,7 +41,7 @@ void DurationConversionCastCheck::check( const auto *FuncDecl = Result.Nodes.getNodeAs<FunctionDecl>("func_decl"); const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg"); - StringRef ConversionFuncName = FuncDecl->getName(); + const StringRef ConversionFuncName = FuncDecl->getName(); std::optional<DurationScale> Scale = getScaleForDurationInverse(ConversionFuncName); @@ -51,7 +51,8 @@ void DurationConversionCastCheck::check( // Casting a double to an integer. if (MatchedCast->getTypeAsWritten()->isIntegerType() && ConversionFuncName.contains("Double")) { - llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).second; + const llvm::StringRef NewFuncName = + getDurationInverseForScale(*Scale).second; diag(MatchedCast->getBeginLoc(), "duration should be converted directly to an integer rather than " @@ -66,7 +67,8 @@ void DurationConversionCastCheck::check( // Casting an integer to a double. if (MatchedCast->getTypeAsWritten()->isRealFloatingType() && ConversionFuncName.contains("Int64")) { - llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).first; + const llvm::StringRef NewFuncName = + getDurationInverseForScale(*Scale).first; diag(MatchedCast->getBeginLoc(), "duration should be converted directly to " "a floating-point number rather than " diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp index 334629767aff2..9e403fb8be3dd 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp @@ -158,7 +158,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) { if (!MaybeScale) return; - DurationScale Scale = *MaybeScale; + const DurationScale Scale = *MaybeScale; const Expr *Remainder = nullptr; std::optional<DurationScale> NewScale; diff --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp index ee1979658aaed..a78d07d2e5861 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp @@ -20,7 +20,7 @@ namespace clang::tidy::abseil { /// Returns an integer if the fractional part of a `FloatingLiteral` is `0`. static std::optional<llvm::APSInt> truncateIfIntegral(const FloatingLiteral &FloatLiteral) { - double Value = FloatLiteral.getValueAsApproximateDouble(); + const double Value = FloatLiteral.getValueAsApproximateDouble(); if (std::fmod(Value, 1) == 0) { if (Value >= static_cast<double>(1U << 31)) return std::nullopt; @@ -69,7 +69,7 @@ rewriteInverseDurationCall(const MatchFinder::MatchResult &Result, static std::optional<std::string> rewriteInverseTimeCall(const MatchFinder::MatchResult &Result, DurationScale Scale, const Expr &Node) { - llvm::StringRef InverseFunction = getTimeInverseForScale(Scale); + const llvm::StringRef InverseFunction = getTimeInverseForScale(Scale); if (const auto *MaybeCallArg = selectFirst<const Expr>( "e", match(callExpr(callee(functionDecl(hasName(InverseFunction))), hasArgument(0, expr().bind("e"))), diff --git a/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp index c5d93ad51ad17..42a7df496f6ad 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp @@ -41,7 +41,7 @@ void DurationSubtractionCheck::check(const MatchFinder::MatchResult &Result) { if (!Scale) return; - std::string RhsReplacement = + const std::string RhsReplacement = rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS()); const Expr *LhsArg = Result.Nodes.getNodeAs<Expr>("lhs_arg"); diff --git a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp index 805d7dacd4eec..5867fb630315d 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp @@ -19,10 +19,10 @@ namespace clang::tidy::abseil { void DurationUnnecessaryConversionCheck::registerMatchers(MatchFinder *Finder) { for (const auto &Scale : {"Hours", "Minutes", "Seconds", "Milliseconds", "Microseconds", "Nanoseconds"}) { - std::string DurationFactory = (llvm::Twine("::absl::") + Scale).str(); - std::string FloatConversion = + const std::string DurationFactory = (llvm::Twine("::absl::") + Scale).str(); + const std::string FloatConversion = (llvm::Twine("::absl::ToDouble") + Scale).str(); - std::string IntegerConversion = + const std::string IntegerConversion = (llvm::Twine("::absl::ToInt64") + Scale).str(); // Matcher which matches the current scale's factory with a `1` argument, diff --git a/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp b/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp index d9f6551739d9e..0827526ba3b5d 100644 --- a/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp @@ -29,7 +29,7 @@ makeCharacterLiteral(const StringLiteral *Literal, const ASTContext &Context) { assert(Literal->getCharByteWidth() == 1 && "StrSplit doesn't support wide char"); std::string Result = clang::tooling::fixit::getText(*Literal, Context).str(); - bool IsRawStringLiteral = StringRef(Result).starts_with(R"(R")"); + const bool IsRawStringLiteral = StringRef(Result).starts_with(R"(R")"); // Since raw string literal might contain unescaped non-printable characters, // we normalize them using `StringLiteral::outputString`. if (IsRawStringLiteral) { diff --git a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp index c090e5ac54222..5f4cb66424700 100644 --- a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp @@ -32,7 +32,7 @@ void NoInternalDependenciesCheck::check( const auto *InternalDependency = Result.Nodes.getNodeAs<NestedNameSpecifierLoc>("InternalDep"); - SourceLocation LocAtFault = + const SourceLocation LocAtFault = Result.SourceManager->getSpellingLoc(InternalDependency->getBeginLoc()); if (!LocAtFault.isValid()) diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp index 92d63057caf65..e1063c4f8a46e 100644 --- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp @@ -92,7 +92,7 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) { const auto *FindFun = Result.Nodes.getNodeAs<CXXMethodDecl>("findfun"); assert(FindFun != nullptr); - bool Rev = FindFun->getName().contains("rfind"); + const bool Rev = FindFun->getName().contains("rfind"); if (ComparisonExpr->getBeginLoc().isMacroID()) return; @@ -107,7 +107,7 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) { Context.getLangOpts()); // Create the StartsWith string, negating if comparison was "!=". - bool Neg = ComparisonExpr->getOpcode() == BO_NE; + const bool Neg = ComparisonExpr->getOpcode() == BO_NE; // Create the warning message and a FixIt hint replacing the original expr. auto Diagnostic = diff --git a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp index 7a97a1895ad02..5d80b16239838 100644 --- a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp @@ -39,9 +39,9 @@ void TimeComparisonCheck::check(const MatchFinder::MatchResult &Result) { // want to handle the case of rewriting both sides. This is much simpler if // we unconditionally try and rewrite both, and let the rewriter determine // if nothing needs to be done. - std::string LhsReplacement = + const std::string LhsReplacement = rewriteExprFromNumberToTime(Result, *Scale, Binop->getLHS()); - std::string RhsReplacement = + const std::string RhsReplacement = rewriteExprFromNumberToTime(Result, *Scale, Binop->getRHS()); diag(Binop->getBeginLoc(), "perform comparison in the time domain") diff --git a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp index 228d974cd5e23..4ae49d285930d 100644 --- a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp @@ -93,7 +93,7 @@ void TimeSubtractionCheck::emitDiagnostic(const Expr *Node, void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) { for (const char *ScaleName : {"Hours", "Minutes", "Seconds", "Millis", "Micros", "Nanos"}) { - std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str(); + const std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str(); std::optional<DurationScale> Scale = getScaleForTimeInverse(TimeInverse); assert(Scale && "Unknown scale encountered"); @@ -127,7 +127,7 @@ void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) { void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) { const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>("binop"); - std::string InverseName = + const std::string InverseName = Result.Nodes.getNodeAs<FunctionDecl>("func_decl")->getNameAsString(); if (insideMacroDefinition(Result, BinOp->getSourceRange())) return; @@ -144,7 +144,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) { // We're working with the first case of matcher, and need to replace the // entire 'Duration' factory call. (Which also means being careful about // our order-of-operations and optionally putting in some parenthesis. - bool NeedParens = parensRequired(Result, OuterCall); + const bool NeedParens = parensRequired(Result, OuterCall); emitDiagnostic( OuterCall, @@ -169,7 +169,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) { // converts it from the inverse to a Duration. In this case, we replace // the outer with just the subtraction expression, which gives the right // type and scale, taking care again about parenthesis. - bool NeedParens = parensRequired(Result, MaybeCallArg); + const bool NeedParens = parensRequired(Result, MaybeCallArg); emitDiagnostic( MaybeCallArg, diff --git a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp index 8b197e5b939e7..1a6ff30fc8d96 100644 --- a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp @@ -117,10 +117,10 @@ void UpgradeDurationConversionsCheck::check( "implicit conversion to 'int64_t' is deprecated in this context; use an " "explicit cast instead"; - TraversalKindScope RAII(*Result.Context, TK_AsIs); + const TraversalKindScope RAII(*Result.Context, TK_AsIs); const auto *ArgExpr = Result.Nodes.getNodeAs<Expr>("arg"); - SourceLocation Loc = ArgExpr->getBeginLoc(); + const SourceLocation Loc = ArgExpr->getBeginLoc(); const auto *OuterExpr = Result.Nodes.getNodeAs<Expr>("OuterExpr"); @@ -139,13 +139,13 @@ void UpgradeDurationConversionsCheck::check( // We gather source locations from template matches not in template // instantiations for future matches. - internal::Matcher<Stmt> IsInsideTemplate = + const internal::Matcher<Stmt> IsInsideTemplate = hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl()))); if (!match(IsInsideTemplate, *ArgExpr, *Result.Context).empty()) MatchedTemplateLocations.insert(Loc); - DiagnosticBuilder Diag = diag(Loc, Message); - CharSourceRange SourceRange = Lexer::makeFileCharRange( + const DiagnosticBuilder Diag = diag(Loc, Message); + const CharSourceRange SourceRange = Lexer::makeFileCharRange( CharSourceRange::getTokenRange(ArgExpr->getSourceRange()), *Result.SourceManager, Result.Context->getLangOpts()); if (SourceRange.isInvalid()) diff --git a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp index 49ba17ce643fe..519d90914580f 100644 --- a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp @@ -76,7 +76,7 @@ void IdDependentBackwardBranchCheck::registerMatchers(MatchFinder *Finder) { this); } -IdDependentBackwardBranchCheck::IdDependencyRecord * +const IdDependentBackwardBranchCheck::IdDependencyRecord * IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) { if (!Expression) return nullptr; @@ -94,12 +94,12 @@ IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) { } for (const auto *Child : Expression->children()) if (const auto *ChildExpression = dyn_cast_if_present<Expr>(Child)) - if (IdDependencyRecord *Result = hasIdDepVar(ChildExpression)) + if (const IdDependencyRecord *Result = hasIdDepVar(ChildExpression)) return Result; return nullptr; } -IdDependentBackwardBranchCheck::IdDependencyRecord * +const IdDependentBackwardBranchCheck::IdDependencyRecord * IdDependentBackwardBranchCheck::hasIdDepField(const Expr *Expression) { if (!Expression) return nullptr; @@ -116,7 +116,7 @@ IdDependentBackwardBranchCheck::hasIdDepField(const Expr *Expression) { } for (const auto *Child : Expression->children()) if (const auto *ChildExpression = dyn_cast_if_present<Expr>(Child)) - if (IdDependencyRecord *Result = hasIdDepField(ChildExpression)) + if (const IdDependencyRecord *Result = hasIdDepField(ChildExpression)) return Result; return nullptr; } @@ -239,7 +239,7 @@ void IdDependentBackwardBranchCheck::check( const auto *Loop = Result.Nodes.getNodeAs<Stmt>("backward_branch"); if (!Loop) return; - LoopType Type = getLoopType(Loop); + const LoopType Type = getLoopType(Loop); if (CondExpr) { if (IDCall) { // Conditional expression calls an ID function directly. diag(CondExpr->getBeginLoc(), @@ -249,8 +249,8 @@ void IdDependentBackwardBranchCheck::check( return; } // Conditional expression has DeclRefExpr(s), check ID-dependency. - IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr); - IdDependencyRecord *IdDepField = hasIdDepField(CondExpr); + const IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr); + const IdDependencyRecord *IdDepField = hasIdDepField(CondExpr); if (IdDepVar) { diag(CondExpr->getBeginLoc(), "backward branch (%select{do|while|for}0 loop) is ID-dependent due " diff --git a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h index b777918ab7e7b..297e7751e4f49 100644 --- a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h +++ b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h @@ -44,10 +44,10 @@ class IdDependentBackwardBranchCheck : public ClangTidyCheck { std::map<const FieldDecl *, IdDependencyRecord> IdDepFieldsMap; /// Returns an IdDependencyRecord if the Expression contains an ID-dependent /// variable, returns a nullptr otherwise. - IdDependencyRecord *hasIdDepVar(const Expr *Expression); + const IdDependencyRecord *hasIdDepVar(const Expr *Expression); /// Returns an IdDependencyRecord if the Expression contains an ID-dependent /// field, returns a nullptr otherwise. - IdDependencyRecord *hasIdDepField(const Expr *Expression); + const IdDependencyRecord *hasIdDepField(const Expr *Expression); /// Stores the location an ID-dependent variable is created from a call to /// an ID function in IdDepVarsMap. void saveIdDepVar(const Stmt *Statement, const VarDecl *Variable); diff --git a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp index 4c740e31ae7be..8aa23b8fc7b11 100644 --- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp @@ -77,7 +77,7 @@ void KernelNameRestrictionPPCallbacks::EndOfMainFile() { // Check main file for restricted names. OptionalFileEntryRef Entry = SM.getFileEntryRefForID(SM.getMainFileID()); - StringRef FileName = llvm::sys::path::filename(Entry->getName()); + const StringRef FileName = llvm::sys::path::filename(Entry->getName()); if (fileNameIsRestricted(FileName)) Check.diag(SM.getLocForStartOfFile(SM.getMainFileID()), "compiling '%0' may cause additional compilation errors due " @@ -90,7 +90,7 @@ void KernelNameRestrictionPPCallbacks::EndOfMainFile() { // Check included files for restricted names. for (const IncludeDirective &ID : IncludeDirectives) { - StringRef FileName = llvm::sys::path::filename(ID.FileName); + const StringRef FileName = llvm::sys::path::filename(ID.FileName); if (fileNameIsRestricted(FileName)) Check.diag(ID.Loc, "including '%0' may cause additional compilation errors due " diff --git a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp index 0a19378949f46..2b1312c8967da 100644 --- a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp @@ -60,10 +60,10 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) { // For each StructField, record how big it is (in bits). // Would be good to use a pair of <offset, size> to advise a better // packing order. - QualType StructFieldTy = StructField->getType(); + const QualType StructFieldTy = StructField->getType(); if (StructFieldTy->isIncompleteType()) return; - unsigned int StructFieldWidth = + const unsigned int StructFieldWidth = (unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr()) .Width; FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex()); @@ -72,21 +72,22 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) { TotalBitSize += StructFieldWidth; } - uint64_t CharSize = Result.Context->getCharWidth(); - CharUnits CurrSize = Result.Context->getASTRecordLayout(Struct).getSize(); - CharUnits MinByteSize = + const uint64_t CharSize = Result.Context->getCharWidth(); + const CharUnits CurrSize = + Result.Context->getASTRecordLayout(Struct).getSize(); + const CharUnits MinByteSize = CharUnits::fromQuantity(std::max<clang::CharUnits::QuantityType>( std::ceil(static_cast<float>(TotalBitSize) / CharSize), 1)); - CharUnits MaxAlign = CharUnits::fromQuantity( + const CharUnits MaxAlign = CharUnits::fromQuantity( std::ceil((float)Struct->getMaxAlignment() / CharSize)); - CharUnits CurrAlign = + const CharUnits CurrAlign = Result.Context->getASTRecordLayout(Struct).getAlignment(); - CharUnits NewAlign = computeRecommendedAlignment(MinByteSize); + const CharUnits NewAlign = computeRecommendedAlignment(MinByteSize); - bool IsPacked = Struct->hasAttr<PackedAttr>(); - bool NeedsPacking = (MinByteSize < CurrSize) && (MaxAlign != NewAlign) && - (CurrSize != NewAlign); - bool NeedsAlignment = CurrAlign.getQuantity() != NewAlign.getQuantity(); + const bool IsPacked = Struct->hasAttr<PackedAttr>(); + const bool NeedsPacking = (MinByteSize < CurrSize) && + (MaxAlign != NewAlign) && (CurrSize != NewAlign); + const bool NeedsAlignment = CurrAlign.getQuantity() != NewAlign.getQuantity(); if (!NeedsAlignment && !NeedsPacking) return; @@ -111,7 +112,8 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) { FixItHint FixIt; auto *Attribute = Struct->getAttr<AlignedAttr>(); - std::string NewAlignQuantity = std::to_string((int)NewAlign.getQuantity()); + const std::string NewAlignQuantity = + std::to_string((int)NewAlign.getQuantity()); if (Attribute) { FixIt = FixItHint::CreateReplacement( Attribute->getRange(), diff --git a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp index e90cdd00eb1fe..b0cd4cdb41e91 100644 --- a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp @@ -127,7 +127,7 @@ bool UnrollLoopsCheck::hasKnownBounds(const Stmt *Statement, if (const auto *InitDeclStatement = dyn_cast<DeclStmt>(Initializer)) { if (const auto *VariableDecl = dyn_cast<VarDecl>(InitDeclStatement->getSingleDecl())) { - APValue *Evaluation = VariableDecl->evaluateValue(); + const APValue *Evaluation = VariableDecl->evaluateValue(); if (!Evaluation || !Evaluation->hasValue()) return false; } diff --git a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp index 9cd888cca023b..a624523b18137 100644 --- a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp +++ b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp @@ -26,10 +26,11 @@ void CloexecAcceptCheck::registerMatchers(MatchFinder *Finder) { } void CloexecAcceptCheck::check(const MatchFinder::MatchResult &Result) { - std::string ReplacementText = (Twine("accept4(") + getSpellingArg(Result, 0) + - ", " + getSpellingArg(Result, 1) + ", " + - getSpellingArg(Result, 2) + ", SOCK_CLOEXEC)") - .str(); + const std::string ReplacementText = + (Twine("accept4(") + getSpellingArg(Result, 0) + ", " + + getSpellingArg(Result, 1) + ", " + getSpellingArg(Result, 2) + + ", SOCK_CLOEXEC)") + .str(); replaceFunc( Result, diff --git a/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp index 48c54c0ae02c3..c046578125590 100644 --- a/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp +++ b/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp @@ -30,7 +30,8 @@ static std::string buildFixMsgForStringFlag(const Expr *Arg, " \"" + Twine(Mode) + "\"") .str(); - StringRef SR = cast<StringLiteral>(Arg->IgnoreParenCasts())->getString(); + const StringRef SR = + cast<StringLiteral>(Arg->IgnoreParenCasts())->getString(); return ("\"" + SR + Twine(Mode) + "\"").str(); } @@ -49,14 +50,14 @@ void CloexecCheck::insertMacroFlag(const MatchFinder::MatchResult &Result, const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>(FuncBindingStr); const auto *FlagArg = MatchedCall->getArg(ArgPos); const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr); - SourceManager &SM = *Result.SourceManager; + const SourceManager &SM = *Result.SourceManager; if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM, Result.Context->getLangOpts(), MacroFlag)) return; - SourceLocation EndLoc = + const SourceLocation EndLoc = Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getEndLoc()), 0, SM, Result.Context->getLangOpts()); @@ -84,7 +85,7 @@ void CloexecCheck::insertStringFlag( if (!ModeStr || ModeStr->getString().contains(Mode)) return; - std::string ReplacementText = buildFixMsgForStringFlag( + const std::string ReplacementText = buildFixMsgForStringFlag( ModeArg, *Result.SourceManager, Result.Context->getLangOpts(), Mode); diag(ModeArg->getBeginLoc(), "use %0 mode '%1' to set O_CLOEXEC") diff --git a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp index 5ac1b6fb632e1..5db57461a5909 100644 --- a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp +++ b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp @@ -20,7 +20,7 @@ void CloexecDupCheck::registerMatchers(MatchFinder *Finder) { } void CloexecDupCheck::check(const MatchFinder::MatchResult &Result) { - std::string ReplacementText = + const std::string ReplacementText = (Twine("fcntl(") + getSpellingArg(Result, 0) + ", F_DUPFD_CLOEXEC)") .str(); diff --git a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp index 8c24482c73251..9938027c53b0e 100644 --- a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp +++ b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp @@ -30,7 +30,7 @@ void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) { void CloexecOpenCheck::check(const MatchFinder::MatchResult &Result) { const auto *FD = Result.Nodes.getNodeAs<FunctionDecl>(FuncDeclBindingStr); assert(FD->param_size() > 1); - int ArgPos = (FD->param_size() > 2) ? 2 : 1; + const int ArgPos = (FD->param_size() > 2) ? 2 : 1; insertMacroFlag(Result, /*MacroFlag=*/"O_CLOEXEC", ArgPos); } diff --git a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp index a475dff4a2682..37e3c56e97021 100644 --- a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp +++ b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp @@ -20,7 +20,7 @@ void CloexecPipeCheck::registerMatchers(MatchFinder *Finder) { } void CloexecPipeCheck::check(const MatchFinder::MatchResult &Result) { - std::string ReplacementText = + const std::string ReplacementText = (Twine("pipe2(") + getSpellingArg(Result, 0) + ", O_CLOEXEC)").str(); replaceFunc(Result, diff --git a/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp b/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp index 36ac9a44695c9..c42f069b487c3 100644 --- a/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp +++ b/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp @@ -64,7 +64,7 @@ void ComparisonInTempFailureRetryCheck::check( const LangOptions &Opts = Result.Context->getLangOpts(); SourceLocation LocStart = Node.getBeginLoc(); while (LocStart.isMacroID()) { - SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart); + const SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart); Token Tok; if (!Lexer::getRawToken(SM.getSpellingLoc(Invocation), Tok, SM, Opts, /*IgnoreWhiteSpace=*/true)) { diff --git a/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp index 34ecee5badb15..02fc8d89a0bf8 100644 --- a/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp +++ b/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp @@ -341,7 +341,7 @@ void UseRangesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { } DiagnosticBuilder UseRangesCheck::createDiag(const CallExpr &Call) { - DiagnosticBuilder D = + const DiagnosticBuilder D = diag(Call.getBeginLoc(), "use a %0 version of this algorithm"); D << (Call.getDirectCallee()->isInStdNamespace() ? "boost" : "ranged"); return D; diff --git a/clang-tools-extra/clang-tidy/objc/AssertEquals.cpp b/clang-tools-extra/clang-tidy/objc/AssertEquals.cpp index 3f1bc17926ba2..0871558b92569 100644 --- a/clang-tools-extra/clang-tidy/objc/AssertEquals.cpp +++ b/clang-tools-extra/clang-tidy/objc/AssertEquals.cpp @@ -17,7 +17,7 @@ namespace clang::tidy::objc { // Mapping from `XCTAssert*Equal` to `XCTAssert*EqualObjects` name. static const std::map<std::string, std::string> &nameMap() { - static std::map<std::string, std::string> Map{ + static const std::map<std::string, std::string> Map{ {"XCTAssertEqual", "XCTAssertEqualObjects"}, {"XCTAssertNotEqual", "XCTAssertNotEqualObjects"}, @@ -44,7 +44,7 @@ void AssertEquals::registerMatchers(MatchFinder *Finder) { void AssertEquals::check(const ast_matchers::MatchFinder::MatchResult &Result) { for (const auto &Pair : nameMap()) { if (const auto *Root = Result.Nodes.getNodeAs<BinaryOperator>(Pair.first)) { - SourceManager *Sm = Result.SourceManager; + const SourceManager *Sm = Result.SourceManager; // The macros are nested two levels, so going up twice. auto MacroCallsite = Sm->getImmediateMacroCallerLoc( Sm->getImmediateMacroCallerLoc(Root->getBeginLoc())); diff --git a/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp b/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp index 1481b2bb24e95..31d098e5034e5 100644 --- a/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp +++ b/clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp @@ -49,7 +49,7 @@ void NSDateFormatterCheck::check(const MatchFinder::MatchResult &Result) { // Callback implementation. const auto *StrExpr = Result.Nodes.getNodeAs<ObjCStringLiteral>("str_lit"); const StringLiteral *SL = cast<ObjCStringLiteral>(StrExpr)->getString(); - StringRef SR = SL->getString(); + const StringRef SR = SL->getString(); if (!isValidDatePattern(SR)) { diag(StrExpr->getExprLoc(), "invalid date format specifier"); diff --git a/clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp b/clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp index 8a32c38a04695..69caaed2b8542 100644 --- a/clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp +++ b/clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp @@ -43,7 +43,7 @@ AST_POLYMORPHIC_MATCHER(isObjCManagedLifetime, AST_POLYMORPHIC_SUPPORTED_TYPES(ObjCIvarRefExpr, DeclRefExpr, MemberExpr)) { - QualType QT = Node.getType(); + const QualType QT = Node.getType(); return QT->isScalarType() && (QT->getScalarTypeKind() == Type::STK_ObjCObjectPointer || QT->getScalarTypeKind() == Type::STK_BlockPointer) && @@ -55,12 +55,12 @@ AST_POLYMORPHIC_MATCHER(isObjCManagedLifetime, static std::optional<FixItHint> fixItHintReplacementForOwnershipString(StringRef Text, CharSourceRange Range, StringRef Ownership) { - size_t Index = Text.find(Ownership); + const size_t Index = Text.find(Ownership); if (Index == StringRef::npos) return std::nullopt; - SourceLocation Begin = Range.getBegin().getLocWithOffset(Index); - SourceLocation End = Begin.getLocWithOffset(Ownership.size()); + const SourceLocation Begin = Range.getBegin().getLocWithOffset(Index); + const SourceLocation End = Begin.getLocWithOffset(Ownership.size()); return FixItHint::CreateReplacement(SourceRange(Begin, End), UnsafeUnretainedText); } @@ -76,7 +76,7 @@ fixItHintForVarDecl(const VarDecl *VD, const SourceManager &SM, // Currently there is no way to directly get the source range for the // __weak/__strong ObjC lifetime qualifiers, so it's necessary to string // search in the source code. - CharSourceRange Range = Lexer::makeFileCharRange( + const CharSourceRange Range = Lexer::makeFileCharRange( CharSourceRange::getTokenRange(VD->getSourceRange()), SM, LangOpts); if (Range.isInvalid()) { // An invalid range likely means inside a macro, in which case don't supply @@ -84,7 +84,7 @@ fixItHintForVarDecl(const VarDecl *VD, const SourceManager &SM, return std::nullopt; } - StringRef VarDeclText = Lexer::getSourceText(Range, SM, LangOpts); + const StringRef VarDeclText = Lexer::getSourceText(Range, SM, LangOpts); if (std::optional<FixItHint> Hint = fixItHintReplacementForOwnershipString(VarDeclText, Range, WeakText)) return Hint; diff --git a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp index 4a586c8ff0ac9..690572ffbf93a 100644 --- a/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp +++ b/clang-tools-extra/clang-tidy/objc/PropertyDeclarationCheck.cpp @@ -39,7 +39,7 @@ static FixItHint generateFixItHint(const ObjCPropertyDecl *Decl, auto NewName = Decl->getName().str(); size_t Index = 0; if (Style == CategoryProperty) { - size_t UnderScorePos = Name.find_first_of('_'); + const size_t UnderScorePos = Name.find_first_of('_'); if (UnderScorePos != llvm::StringRef::npos) { Index = UnderScorePos + 1; NewName.replace(0, Index - 1, Name.substr(0, Index - 1).lower()); @@ -74,7 +74,7 @@ static std::string validPropertyNameRegex(bool UsedInMatcher) { // // aRbITRaRyCapS is allowed to avoid generating false positives for names // like isVitaminBSupplement, CProgrammingLanguage, and isBeforeM. - std::string StartMatcher = UsedInMatcher ? "::" : "^"; + const std::string StartMatcher = UsedInMatcher ? "::" : "^"; return StartMatcher + "([a-z]|[A-Z][A-Z0-9])[a-z0-9A-Z]*$"; } @@ -85,7 +85,7 @@ static bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) { } static bool prefixedPropertyNameValid(llvm::StringRef PropertyName) { - size_t Start = PropertyName.find_first_of('_'); + const size_t Start = PropertyName.find_first_of('_'); assert(Start != llvm::StringRef::npos && Start + 1 < PropertyName.size()); auto Prefix = PropertyName.substr(0, Start); if (Prefix.lower() != Prefix) { @@ -115,8 +115,9 @@ void PropertyDeclarationCheck::check(const MatchFinder::MatchResult &Result) { hasCategoryPropertyPrefix(MatchedDecl->getName())) { if (!prefixedPropertyNameValid(MatchedDecl->getName()) || CategoryDecl->IsClassExtension()) { - NamingStyle Style = CategoryDecl->IsClassExtension() ? StandardProperty - : CategoryProperty; + const NamingStyle Style = CategoryDecl->IsClassExtension() + ? StandardProperty + : CategoryProperty; diag(MatchedDecl->getLocation(), "property name '%0' not using lowerCamelCase style or not prefixed " "in a category, according to the Apple Coding Guidelines") diff --git a/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp b/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp index 3c133ad7dd96b..3887afe703389 100644 --- a/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp +++ b/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp @@ -90,11 +90,11 @@ void SuperSelfCheck::check(const MatchFinder::MatchResult &Result) { "invoke a superclass initializer?") << Message->getMethodDecl(); - SourceLocation ReceiverLoc = Message->getReceiverRange().getBegin(); + const SourceLocation ReceiverLoc = Message->getReceiverRange().getBegin(); if (ReceiverLoc.isMacroID() || ReceiverLoc.isInvalid()) return; - SourceLocation SelectorLoc = Message->getSelectorStartLoc(); + const SourceLocation SelectorLoc = Message->getSelectorStartLoc(); if (SelectorLoc.isMacroID() || SelectorLoc.isInvalid()) return; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
