Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 "
Expand All @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void IdDependentBackwardBranchCheck::registerMatchers(MatchFinder *Finder) {
this);
}

IdDependentBackwardBranchCheck::IdDependencyRecord *
const IdDependentBackwardBranchCheck::IdDependencyRecord *
IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) {
if (!Expression)
return nullptr;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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(),
Expand All @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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 "
Expand Down
28 changes: 15 additions & 13 deletions clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
Expand All @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading