Skip to content

Commit 913849e

Browse files
authored
[clang-tidy][NFC] Fix misc-const-correctness warnings (2/N) (#167035)
1 parent 11efce4 commit 913849e

12 files changed

+85
-82
lines changed

clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void MultiwayPathsCoveredCheck::handleSwitchWithoutDefault(
152152
assert(CaseCount > 0 && "Switch statement without any case found. This case "
153153
"should be excluded by the matcher and is handled "
154154
"separately.");
155-
std::size_t MaxPathsPossible = [&]() {
155+
const std::size_t MaxPathsPossible = [&]() {
156156
if (const auto *GeneralCondition =
157157
Result.Nodes.getNodeAs<DeclRefExpr>("non-enum-condition")) {
158158
return getNumberOfPossibleValues(GeneralCondition->getType(),

clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@ std::string LLVMHeaderGuardCheck::getHeaderGuard(StringRef Filename,
2828
// style in include/llvm and include/clang which we want to preserve.
2929

3030
// We don't want _INCLUDE_ in our guards.
31-
size_t PosInclude = Guard.rfind("include/");
31+
const size_t PosInclude = Guard.rfind("include/");
3232
if (PosInclude != StringRef::npos)
3333
Guard = Guard.substr(PosInclude + std::strlen("include/"));
3434

3535
// For clang we drop the _TOOLS_.
36-
size_t PosToolsClang = Guard.rfind("tools/clang/");
36+
const size_t PosToolsClang = Guard.rfind("tools/clang/");
3737
if (PosToolsClang != StringRef::npos)
3838
Guard = Guard.substr(PosToolsClang + std::strlen("tools/"));
3939

4040
// Unlike LLVM svn, LLVM git monorepo is named llvm-project, so we replace
4141
// "/llvm-project/" with the canonical "/llvm/".
4242
const static StringRef LLVMProject = "/llvm-project/";
43-
size_t PosLLVMProject = Guard.rfind(LLVMProject);
43+
const size_t PosLLVMProject = Guard.rfind(LLVMProject);
4444
if (PosLLVMProject != StringRef::npos)
4545
Guard = Guard.replace(PosLLVMProject, LLVMProject.size(), "/llvm/");
4646

4747
// The remainder is LLVM_FULL_PATH_TO_HEADER_H
48-
size_t PosLLVM = Guard.rfind("llvm/");
48+
const size_t PosLLVM = Guard.rfind("llvm/");
4949
if (PosLLVM != StringRef::npos)
5050
Guard = Guard.substr(PosLLVM);
5151

clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ void IncludeOrderPPCallbacks::EndOfMainFile() {
162162
continue;
163163
const IncludeDirective &CopyFrom = FileDirectives[IncludeIndices[I]];
164164

165-
SourceLocation FromLoc = CopyFrom.Range.getBegin();
165+
const SourceLocation FromLoc = CopyFrom.Range.getBegin();
166166
const char *FromData = SM.getCharacterData(FromLoc);
167-
unsigned FromLen = std::strcspn(FromData, "\n");
167+
const unsigned FromLen = std::strcspn(FromData, "\n");
168168

169-
StringRef FixedName(FromData, FromLen);
169+
const StringRef FixedName(FromData, FromLen);
170170

171-
SourceLocation ToLoc = FileDirectives[I].Range.getBegin();
171+
const SourceLocation ToLoc = FileDirectives[I].Range.getBegin();
172172
const char *ToData = SM.getCharacterData(ToLoc);
173-
unsigned ToLen = std::strcspn(ToData, "\n");
173+
const unsigned ToLen = std::strcspn(ToData, "\n");
174174
auto ToRange =
175175
CharSourceRange::getCharRange(ToLoc, ToLoc.getLocWithOffset(ToLen));
176176

clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void PreferIsaOrDynCastInConditionalsCheck::check(
6868
// llvm::cast<T>(x)
6969
// ^ ^
7070
// StartLoc EndLoc
71-
SourceLocation StartLoc = Callee->getLocation();
72-
SourceLocation EndLoc = Callee->getNameInfo().getEndLoc();
71+
const SourceLocation StartLoc = Callee->getLocation();
72+
const SourceLocation EndLoc = Callee->getNameInfo().getEndLoc();
7373

7474
if (Result.Nodes.getNodeAs<VarDecl>("var")) {
7575
diag(StartLoc,

clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ void TwineLocalCheck::check(const MatchFinder::MatchResult &Result) {
4040
C = cast<CXXConstructExpr>(C)->getArg(0)->IgnoreParenImpCasts();
4141
}
4242

43-
SourceRange TypeRange =
43+
const SourceRange TypeRange =
4444
VD->getTypeSourceInfo()->getTypeLoc().getSourceRange();
4545

4646
// A real Twine, turn it into a std::string.
4747
if (VD->getType()->getCanonicalTypeUnqualified() ==
4848
C->getType()->getCanonicalTypeUnqualified()) {
49-
SourceLocation EndLoc = Lexer::getLocForEndOfToken(
49+
const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
5050
VD->getInit()->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
5151
Diag << FixItHint::CreateReplacement(TypeRange, "std::string")
5252
<< FixItHint::CreateInsertion(VD->getInit()->getBeginLoc(), "(")

clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static EditGenerator rewrite(RangeSelector Call, RangeSelector Builder) {
3636
SourceLocation Begin = CallRange->getBegin();
3737

3838
// This will result in just a warning and no edit.
39-
bool InMacro = CallRange->getBegin().isMacroID();
39+
const bool InMacro = CallRange->getBegin().isMacroID();
4040
if (InMacro) {
4141
while (SM.isMacroArgExpansion(Begin))
4242
Begin = SM.getImmediateExpansionRange(Begin).getBegin();
@@ -119,11 +119,11 @@ static EditGenerator rewrite(RangeSelector Call, RangeSelector Builder) {
119119
}
120120

121121
static RewriteRuleWith<std::string> useNewMlirOpBuilderCheckRule() {
122-
Stencil Message = cat("use 'OpType::create(builder, ...)' instead of "
123-
"'builder.create<OpType>(...)'");
122+
const Stencil Message = cat("use 'OpType::create(builder, ...)' instead of "
123+
"'builder.create<OpType>(...)'");
124124
// Match a create call on an OpBuilder.
125125
auto BuilderType = cxxRecordDecl(isSameOrDerivedFrom("::mlir::OpBuilder"));
126-
ast_matchers::internal::Matcher<Stmt> Base =
126+
const ast_matchers::internal::Matcher<Stmt> Base =
127127
cxxMemberCallExpr(
128128
on(expr(anyOf(hasType(BuilderType), hasType(pointsTo(BuilderType))))
129129
.bind("builder")),

clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ void InlineFunctionDeclCheck::check(const MatchFinder::MatchResult &Result) {
7878
// Check if decl starts with LIBC_INLINE
7979
auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
8080
*Result.SourceManager);
81-
llvm::StringRef SrcText = Loc.getBufferData().drop_front(Loc.getFileOffset());
81+
const llvm::StringRef SrcText =
82+
Loc.getBufferData().drop_front(Loc.getFileOffset());
8283
if (SrcText.starts_with("LIBC_INLINE"))
8384
return;
8485

clang-tools-extra/clang-tidy/mpi/TypeMismatchCheck.cpp

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,39 @@ isMPITypeMatching(const std::multimap<BuiltinType::Kind, StringRef> &MultiMap,
4141
///
4242
/// \returns true if the type is a standard type
4343
static bool isStandardMPIDatatype(StringRef MPIDatatype) {
44-
static llvm::StringSet<> AllTypes = {"MPI_C_BOOL",
45-
"MPI_CHAR",
46-
"MPI_SIGNED_CHAR",
47-
"MPI_UNSIGNED_CHAR",
48-
"MPI_WCHAR",
49-
"MPI_INT",
50-
"MPI_LONG",
51-
"MPI_SHORT",
52-
"MPI_LONG_LONG",
53-
"MPI_LONG_LONG_INT",
54-
"MPI_UNSIGNED",
55-
"MPI_UNSIGNED_SHORT",
56-
"MPI_UNSIGNED_LONG",
57-
"MPI_UNSIGNED_LONG_LONG",
58-
"MPI_FLOAT",
59-
"MPI_DOUBLE",
60-
"MPI_LONG_DOUBLE",
61-
"MPI_C_COMPLEX",
62-
"MPI_C_FLOAT_COMPLEX",
63-
"MPI_C_DOUBLE_COMPLEX",
64-
"MPI_C_LONG_DOUBLE_COMPLEX",
65-
"MPI_INT8_T",
66-
"MPI_INT16_T",
67-
"MPI_INT32_T",
68-
"MPI_INT64_T",
69-
"MPI_UINT8_T",
70-
"MPI_UINT16_T",
71-
"MPI_UINT32_T",
72-
"MPI_UINT64_T",
73-
"MPI_CXX_BOOL",
74-
"MPI_CXX_FLOAT_COMPLEX",
75-
"MPI_CXX_DOUBLE_COMPLEX",
76-
"MPI_CXX_LONG_DOUBLE_COMPLEX"};
44+
static const llvm::StringSet<> AllTypes = {"MPI_C_BOOL",
45+
"MPI_CHAR",
46+
"MPI_SIGNED_CHAR",
47+
"MPI_UNSIGNED_CHAR",
48+
"MPI_WCHAR",
49+
"MPI_INT",
50+
"MPI_LONG",
51+
"MPI_SHORT",
52+
"MPI_LONG_LONG",
53+
"MPI_LONG_LONG_INT",
54+
"MPI_UNSIGNED",
55+
"MPI_UNSIGNED_SHORT",
56+
"MPI_UNSIGNED_LONG",
57+
"MPI_UNSIGNED_LONG_LONG",
58+
"MPI_FLOAT",
59+
"MPI_DOUBLE",
60+
"MPI_LONG_DOUBLE",
61+
"MPI_C_COMPLEX",
62+
"MPI_C_FLOAT_COMPLEX",
63+
"MPI_C_DOUBLE_COMPLEX",
64+
"MPI_C_LONG_DOUBLE_COMPLEX",
65+
"MPI_INT8_T",
66+
"MPI_INT16_T",
67+
"MPI_INT32_T",
68+
"MPI_INT64_T",
69+
"MPI_UINT8_T",
70+
"MPI_UINT16_T",
71+
"MPI_UINT32_T",
72+
"MPI_UINT64_T",
73+
"MPI_CXX_BOOL",
74+
"MPI_CXX_FLOAT_COMPLEX",
75+
"MPI_CXX_DOUBLE_COMPLEX",
76+
"MPI_CXX_LONG_DOUBLE_COMPLEX"};
7777

7878
return AllTypes.contains(MPIDatatype);
7979
}
@@ -90,7 +90,7 @@ static bool isBuiltinTypeMatching(const BuiltinType *Builtin,
9090
std::string &BufferTypeName,
9191
StringRef MPIDatatype,
9292
const LangOptions &LO) {
93-
static std::multimap<BuiltinType::Kind, StringRef> BuiltinMatches = {
93+
static const std::multimap<BuiltinType::Kind, StringRef> BuiltinMatches = {
9494
// On some systems like PPC or ARM, 'char' is unsigned by default which is
9595
// why distinct signedness for the buffer and MPI type is tolerated.
9696
{BuiltinType::SChar, "MPI_CHAR"},
@@ -143,7 +143,7 @@ static bool isCComplexTypeMatching(const ComplexType *const Complex,
143143
std::string &BufferTypeName,
144144
StringRef MPIDatatype,
145145
const LangOptions &LO) {
146-
static std::multimap<BuiltinType::Kind, StringRef> ComplexCMatches = {
146+
static const std::multimap<BuiltinType::Kind, StringRef> ComplexCMatches = {
147147
{BuiltinType::Float, "MPI_C_COMPLEX"},
148148
{BuiltinType::Float, "MPI_C_FLOAT_COMPLEX"},
149149
{BuiltinType::Double, "MPI_C_DOUBLE_COMPLEX"},
@@ -173,7 +173,7 @@ static bool
173173
isCXXComplexTypeMatching(const TemplateSpecializationType *const Template,
174174
std::string &BufferTypeName, StringRef MPIDatatype,
175175
const LangOptions &LO) {
176-
static std::multimap<BuiltinType::Kind, StringRef> ComplexCXXMatches = {
176+
static const std::multimap<BuiltinType::Kind, StringRef> ComplexCXXMatches = {
177177
{BuiltinType::Float, "MPI_CXX_FLOAT_COMPLEX"},
178178
{BuiltinType::Double, "MPI_CXX_DOUBLE_COMPLEX"},
179179
{BuiltinType::LongDouble, "MPI_CXX_LONG_DOUBLE_COMPLEX"}};
@@ -264,7 +264,7 @@ void TypeMismatchCheck::check(const MatchFinder::MatchResult &Result) {
264264
"MPI_IN_PLACE")
265265
return;
266266

267-
StringRef MPIDatatype =
267+
const StringRef MPIDatatype =
268268
tooling::fixit::getText(*CE->getArg(DatatypeIdx), *Result.Context);
269269

270270
const Type *ArgType = argumentType(CE, BufferIdx);

clang-tools-extra/clang-tidy/plugin/ClangTidyPlugin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ class ClangTidyPluginAction : public PluginASTAction {
5555

5656
bool ParseArgs(const CompilerInstance &,
5757
const std::vector<std::string> &Args) override {
58-
ClangTidyGlobalOptions GlobalOptions;
59-
ClangTidyOptions DefaultOptions;
58+
const ClangTidyGlobalOptions GlobalOptions;
59+
const ClangTidyOptions DefaultOptions;
6060
ClangTidyOptions OverrideOptions;
6161

6262
// Parse the extra command line args.
6363
// FIXME: This is very limited at the moment.
64-
for (StringRef Arg : Args)
64+
for (const StringRef Arg : Args)
6565
if (Arg.starts_with("-checks="))
6666
OverrideOptions.Checks = std::string(Arg.substr(strlen("-checks=")));
6767

clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ void RestrictedIncludesPPCallbacks::EndOfMainFile() {
4343
for (const auto &Include : FileDirectives) {
4444
// Fetch the length of the include statement from the start to just after
4545
// the newline, for finding the end (including the newline).
46-
unsigned ToLen = std::strcspn(SM.getCharacterData(Include.Loc), "\n") + 1;
47-
CharSourceRange ToRange = CharSourceRange::getCharRange(
46+
const unsigned ToLen =
47+
std::strcspn(SM.getCharacterData(Include.Loc), "\n") + 1;
48+
const CharSourceRange ToRange = CharSourceRange::getCharRange(
4849
Include.Loc, Include.Loc.getLocWithOffset(ToLen));
4950

5051
if (!Include.IsInMainFile) {

0 commit comments

Comments
 (0)