Skip to content

Commit 554717f

Browse files
authored
Merge branch 'main' into hgh/libcxx/clean-up_saturation_arithmetic_tests
2 parents 78927c6 + 42ddb55 commit 554717f

File tree

138 files changed

+10850
-10297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+10850
-10297
lines changed

.ci/metrics/requirements.lock.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,18 @@ pynacl==1.5.0 \
247247
--hash=sha256:a422368fc821589c228f4c49438a368831cb5bbc0eab5ebe1d7fac9dded6567b \
248248
--hash=sha256:e46dae94e34b085175f8abb3b0aaa7da40767865ac82c928eeb9e57e1ea8a543
249249
# via pygithub
250+
python-dateutil==2.9.0.post0 \
251+
--hash=sha256:37dd54208da7e1cd875388217d5e00ebd4179249f90fb72437e91a35459a0ad3 \
252+
--hash=sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427
253+
# via -r ./requirements.txt
250254
requests==2.32.3 \
251255
--hash=sha256:55365417734eb18255590a9ff9eb97e9e1da868d4ccd6402399eaf68af20a760 \
252256
--hash=sha256:70761cfe03c773ceb22aa2f671b4757976145175cdfca038c02654d061d6dcc6
253257
# via pygithub
258+
six==1.17.0 \
259+
--hash=sha256:4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274 \
260+
--hash=sha256:ff70335d468e7eb6ec65b95b99d3a2836546063f63acc5171de367e834932a81
261+
# via python-dateutil
254262
typing-extensions==4.12.2 \
255263
--hash=sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d \
256264
--hash=sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8

.ci/metrics/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pygithub==2.5.0
2+
python-dateutil==2.9.0.post0

clang-tools-extra/clang-query/Query.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
114114
Profiler.emplace();
115115

116116
for (auto &AST : QS.ASTs) {
117-
ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
117+
ast_matchers::MatchFinderOptions FinderOptions;
118118
std::optional<llvm::StringMap<llvm::TimeRecord>> Records;
119119
if (QS.EnableProfile) {
120120
Records.emplace();

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ ClangTidyASTConsumerFactory::createASTConsumer(
420420
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
421421
CheckFactories->createChecksForLanguage(&Context);
422422

423-
ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
423+
ast_matchers::MatchFinderOptions FinderOptions;
424424

425425
std::unique_ptr<ClangTidyProfiling> Profiling;
426426
if (Context.getEnableProfiling()) {
@@ -429,6 +429,10 @@ ClangTidyASTConsumerFactory::createASTConsumer(
429429
FinderOptions.CheckProfiling.emplace(Profiling->Records);
430430
}
431431

432+
// Avoid processing system headers, unless the user explicitly requests it
433+
if (!Context.getOptions().SystemHeaders.value_or(false))
434+
FinderOptions.SkipSystemHeaders = true;
435+
432436
std::unique_ptr<ast_matchers::MatchFinder> Finder(
433437
new ast_matchers::MatchFinder(std::move(FinderOptions)));
434438

clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,41 @@ AST_POLYMORPHIC_MATCHER_P(
3535
Builder) != Args.end();
3636
}
3737

38+
bool isStdOrPosixImpl(const DeclContext *Ctx) {
39+
if (!Ctx->isNamespace())
40+
return false;
41+
42+
const auto *ND = cast<NamespaceDecl>(Ctx);
43+
if (ND->isInline()) {
44+
return isStdOrPosixImpl(ND->getParent());
45+
}
46+
47+
if (!ND->getParent()->getRedeclContext()->isTranslationUnit())
48+
return false;
49+
50+
const IdentifierInfo *II = ND->getIdentifier();
51+
return II && (II->isStr("std") || II->isStr("posix"));
52+
}
53+
54+
AST_MATCHER(Decl, isInStdOrPosixNS) {
55+
for (const auto *Ctx = Node.getDeclContext(); Ctx; Ctx = Ctx->getParent()) {
56+
if (isStdOrPosixImpl(Ctx))
57+
return true;
58+
}
59+
return false;
60+
}
61+
3862
} // namespace
3963

4064
namespace clang::tidy::cert {
4165

4266
void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
4367
auto HasStdParent =
4468
hasDeclContext(namespaceDecl(hasAnyName("std", "posix"),
45-
unless(hasParent(namespaceDecl())))
69+
unless(hasDeclContext(namespaceDecl())))
4670
.bind("nmspc"));
47-
auto UserDefinedType = qualType(
48-
hasUnqualifiedDesugaredType(tagType(unless(hasDeclaration(tagDecl(
49-
hasAncestor(namespaceDecl(hasAnyName("std", "posix"),
50-
unless(hasParent(namespaceDecl()))))))))));
71+
auto UserDefinedType = qualType(hasUnqualifiedDesugaredType(
72+
tagType(unless(hasDeclaration(tagDecl(isInStdOrPosixNS()))))));
5173
auto HasNoProgramDefinedTemplateArgument = unless(
5274
hasAnyTemplateArgumentIncludingPack(refersToType(UserDefinedType)));
5375
auto InsideStdClassOrClassTemplateSpecialization = hasDeclContext(

clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp

Lines changed: 118 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "clang/AST/ASTContext.h"
1414
#include "clang/ASTMatchers/ASTMatchFinder.h"
1515
#include "clang/ASTMatchers/ASTMatchers.h"
16+
#include <cassert>
1617

1718
using namespace clang::ast_matchers;
1819

@@ -37,36 +38,54 @@ AST_MATCHER(Type, isDependentType) { return Node.isDependentType(); }
3738
ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
3839
ClangTidyContext *Context)
3940
: ClangTidyCheck(Name, Context),
40-
AnalyzeValues(Options.get("AnalyzeValues", true)),
41+
AnalyzePointers(Options.get("AnalyzePointers", true)),
4142
AnalyzeReferences(Options.get("AnalyzeReferences", true)),
43+
AnalyzeValues(Options.get("AnalyzeValues", true)),
44+
45+
WarnPointersAsPointers(Options.get("WarnPointersAsPointers", true)),
4246
WarnPointersAsValues(Options.get("WarnPointersAsValues", false)),
43-
TransformValues(Options.get("TransformValues", true)),
44-
TransformReferences(Options.get("TransformReferences", true)),
47+
48+
TransformPointersAsPointers(
49+
Options.get("TransformPointersAsPointers", true)),
4550
TransformPointersAsValues(
4651
Options.get("TransformPointersAsValues", false)),
52+
TransformReferences(Options.get("TransformReferences", true)),
53+
TransformValues(Options.get("TransformValues", true)),
54+
4755
AllowedTypes(
4856
utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
49-
if (AnalyzeValues == false && AnalyzeReferences == false)
57+
if (AnalyzeValues == false && AnalyzeReferences == false &&
58+
AnalyzePointers == false)
5059
this->configurationDiag(
5160
"The check 'misc-const-correctness' will not "
52-
"perform any analysis because both 'AnalyzeValues' and "
53-
"'AnalyzeReferences' are false.");
61+
"perform any analysis because 'AnalyzeValues', "
62+
"'AnalyzeReferences' and 'AnalyzePointers' are false.");
5463
}
5564

5665
void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
57-
Options.store(Opts, "AnalyzeValues", AnalyzeValues);
66+
Options.store(Opts, "AnalyzePointers", AnalyzePointers);
5867
Options.store(Opts, "AnalyzeReferences", AnalyzeReferences);
68+
Options.store(Opts, "AnalyzeValues", AnalyzeValues);
69+
70+
Options.store(Opts, "WarnPointersAsPointers", WarnPointersAsPointers);
5971
Options.store(Opts, "WarnPointersAsValues", WarnPointersAsValues);
6072

61-
Options.store(Opts, "TransformValues", TransformValues);
62-
Options.store(Opts, "TransformReferences", TransformReferences);
73+
Options.store(Opts, "TransformPointersAsPointers",
74+
TransformPointersAsPointers);
6375
Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
76+
Options.store(Opts, "TransformReferences", TransformReferences);
77+
Options.store(Opts, "TransformValues", TransformValues);
78+
6479
Options.store(Opts, "AllowedTypes",
6580
utils::options::serializeStringList(AllowedTypes));
6681
}
6782

6883
void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
69-
const auto ConstType = hasType(isConstQualified());
84+
const auto ConstType = hasType(
85+
qualType(isConstQualified(),
86+
// pointee check will check the const pointer and const array
87+
unless(pointerType()), unless(arrayType())));
88+
7089
const auto ConstReference = hasType(references(isConstQualified()));
7190
const auto RValueReference = hasType(
7291
referenceType(anyOf(rValueReferenceType(), unless(isSpelledAsLValue()))));
@@ -124,6 +143,11 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
124143
const auto *LocalScope = Result.Nodes.getNodeAs<Stmt>("scope");
125144
const auto *Variable = Result.Nodes.getNodeAs<VarDecl>("local-value");
126145
const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("function-decl");
146+
const auto *VarDeclStmt = Result.Nodes.getNodeAs<DeclStmt>("decl-stmt");
147+
// It can not be guaranteed that the variable is declared isolated,
148+
// therefore a transformation might effect the other variables as well and
149+
// be incorrect.
150+
const bool CanBeFixIt = VarDeclStmt != nullptr && VarDeclStmt->isSingleDecl();
127151

128152
/// If the variable was declared in a template it might be analyzed multiple
129153
/// times. Only one of those instantiations shall emit a warning. NOTE: This
@@ -137,72 +161,102 @@ void ConstCorrectnessCheck::check(const MatchFinder::MatchResult &Result) {
137161

138162
VariableCategory VC = VariableCategory::Value;
139163
const QualType VT = Variable->getType();
140-
if (VT->isReferenceType())
164+
if (VT->isReferenceType()) {
141165
VC = VariableCategory::Reference;
142-
else if (VT->isPointerType())
166+
} else if (VT->isPointerType()) {
143167
VC = VariableCategory::Pointer;
144-
else if (const auto *ArrayT = dyn_cast<ArrayType>(VT))
168+
} else if (const auto *ArrayT = dyn_cast<ArrayType>(VT)) {
145169
if (ArrayT->getElementType()->isPointerType())
146170
VC = VariableCategory::Pointer;
171+
}
147172

148-
// Each variable can only be in one category: Value, Pointer, Reference.
149-
// Analysis can be controlled for every category.
150-
if (VC == VariableCategory::Reference && !AnalyzeReferences)
151-
return;
152-
153-
if (VC == VariableCategory::Reference &&
154-
Variable->getType()->getPointeeType()->isPointerType() &&
155-
!WarnPointersAsValues)
156-
return;
157-
158-
if (VC == VariableCategory::Pointer && !WarnPointersAsValues)
159-
return;
160-
161-
if (VC == VariableCategory::Value && !AnalyzeValues)
162-
return;
163-
164-
// The scope is only registered if the analysis shall be run.
165-
registerScope(LocalScope, Result.Context);
166-
167-
// Offload const-analysis to utility function.
168-
if (ScopesCache[LocalScope]->isMutated(Variable))
169-
return;
170-
171-
auto Diag = diag(Variable->getBeginLoc(),
172-
"variable %0 of type %1 can be declared 'const'")
173-
<< Variable << Variable->getType();
174-
if (IsNormalVariableInTemplate)
175-
TemplateDiagnosticsCache.insert(Variable->getBeginLoc());
173+
auto CheckValue = [&]() {
174+
// The scope is only registered if the analysis shall be run.
175+
registerScope(LocalScope, Result.Context);
176+
177+
// Offload const-analysis to utility function.
178+
if (ScopesCache[LocalScope]->isMutated(Variable))
179+
return;
180+
181+
auto Diag = diag(Variable->getBeginLoc(),
182+
"variable %0 of type %1 can be declared 'const'")
183+
<< Variable << VT;
184+
if (IsNormalVariableInTemplate)
185+
TemplateDiagnosticsCache.insert(Variable->getBeginLoc());
186+
if (!CanBeFixIt)
187+
return;
188+
using namespace utils::fixit;
189+
if (VC == VariableCategory::Value && TransformValues) {
190+
Diag << addQualifierToVarDecl(*Variable, *Result.Context,
191+
Qualifiers::Const, QualifierTarget::Value,
192+
QualifierPolicy::Right);
193+
// FIXME: Add '{}' for default initialization if no user-defined default
194+
// constructor exists and there is no initializer.
195+
return;
196+
}
176197

177-
const auto *VarDeclStmt = Result.Nodes.getNodeAs<DeclStmt>("decl-stmt");
198+
if (VC == VariableCategory::Reference && TransformReferences) {
199+
Diag << addQualifierToVarDecl(*Variable, *Result.Context,
200+
Qualifiers::Const, QualifierTarget::Value,
201+
QualifierPolicy::Right);
202+
return;
203+
}
178204

179-
// It can not be guaranteed that the variable is declared isolated, therefore
180-
// a transformation might effect the other variables as well and be incorrect.
181-
if (VarDeclStmt == nullptr || !VarDeclStmt->isSingleDecl())
182-
return;
205+
if (VC == VariableCategory::Pointer && TransformPointersAsValues) {
206+
Diag << addQualifierToVarDecl(*Variable, *Result.Context,
207+
Qualifiers::Const, QualifierTarget::Value,
208+
QualifierPolicy::Right);
209+
return;
210+
}
211+
};
212+
213+
auto CheckPointee = [&]() {
214+
assert(VC == VariableCategory::Pointer);
215+
registerScope(LocalScope, Result.Context);
216+
if (ScopesCache[LocalScope]->isPointeeMutated(Variable))
217+
return;
218+
auto Diag =
219+
diag(Variable->getBeginLoc(),
220+
"pointee of variable %0 of type %1 can be declared 'const'")
221+
<< Variable << VT;
222+
if (IsNormalVariableInTemplate)
223+
TemplateDiagnosticsCache.insert(Variable->getBeginLoc());
224+
if (!CanBeFixIt)
225+
return;
226+
using namespace utils::fixit;
227+
if (TransformPointersAsPointers) {
228+
Diag << addQualifierToVarDecl(*Variable, *Result.Context,
229+
Qualifiers::Const, QualifierTarget::Pointee,
230+
QualifierPolicy::Right);
231+
}
232+
};
183233

184-
using namespace utils::fixit;
185-
if (VC == VariableCategory::Value && TransformValues) {
186-
Diag << addQualifierToVarDecl(*Variable, *Result.Context, Qualifiers::Const,
187-
QualifierTarget::Value,
188-
QualifierPolicy::Right);
189-
// FIXME: Add '{}' for default initialization if no user-defined default
190-
// constructor exists and there is no initializer.
234+
// Each variable can only be in one category: Value, Pointer, Reference.
235+
// Analysis can be controlled for every category.
236+
if (VC == VariableCategory::Value && AnalyzeValues) {
237+
CheckValue();
191238
return;
192239
}
193-
194-
if (VC == VariableCategory::Reference && TransformReferences) {
195-
Diag << addQualifierToVarDecl(*Variable, *Result.Context, Qualifiers::Const,
196-
QualifierTarget::Value,
197-
QualifierPolicy::Right);
240+
if (VC == VariableCategory::Reference && AnalyzeReferences) {
241+
if (VT->getPointeeType()->isPointerType() && !WarnPointersAsValues)
242+
return;
243+
CheckValue();
198244
return;
199245
}
200-
201-
if (VC == VariableCategory::Pointer) {
202-
if (WarnPointersAsValues && TransformPointersAsValues) {
203-
Diag << addQualifierToVarDecl(*Variable, *Result.Context,
204-
Qualifiers::Const, QualifierTarget::Value,
205-
QualifierPolicy::Right);
246+
if (VC == VariableCategory::Pointer && AnalyzePointers) {
247+
if (WarnPointersAsValues && !VT.isConstQualified())
248+
CheckValue();
249+
if (WarnPointersAsPointers) {
250+
if (const auto *PT = dyn_cast<PointerType>(VT)) {
251+
if (!PT->getPointeeType().isConstQualified())
252+
CheckPointee();
253+
}
254+
if (const auto *AT = dyn_cast<ArrayType>(VT)) {
255+
if (!AT->getElementType().isConstQualified()) {
256+
assert(AT->getElementType()->isPointerType());
257+
CheckPointee();
258+
}
259+
}
206260
}
207261
return;
208262
}

clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
3838
llvm::DenseMap<const Stmt *, MutationAnalyzer> ScopesCache;
3939
llvm::DenseSet<SourceLocation> TemplateDiagnosticsCache;
4040

41-
const bool AnalyzeValues;
41+
const bool AnalyzePointers;
4242
const bool AnalyzeReferences;
43+
const bool AnalyzeValues;
44+
45+
const bool WarnPointersAsPointers;
4346
const bool WarnPointersAsValues;
4447

45-
const bool TransformValues;
46-
const bool TransformReferences;
48+
const bool TransformPointersAsPointers;
4749
const bool TransformPointersAsValues;
50+
const bool TransformReferences;
51+
const bool TransformValues;
52+
4853
const std::vector<StringRef> AllowedTypes;
4954
};
5055

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ Improvements to clang-query
9191
Improvements to clang-tidy
9292
--------------------------
9393

94+
- :program:`clang-tidy` no longer processes declarations from system headers
95+
by default, greatly improving performance. This behavior is disabled if the
96+
`SystemHeaders` option is enabled.
97+
Note: this may lead to false negatives; downstream users may need to adjust
98+
their checks to preserve existing behavior.
99+
94100
New checks
95101
^^^^^^^^^^
96102

@@ -136,7 +142,8 @@ Changes in existing checks
136142
<clang-tidy/checks/misc/const-correctness>` check by adding the option
137143
`AllowedTypes`, that excludes specified types from const-correctness
138144
checking and fixing false positives when modifying variant by ``operator[]``
139-
with template in parameters.
145+
with template in parameters and supporting to check pointee mutation by
146+
`AnalyzePointers` option.
140147

141148
- Improved :doc:`misc-redundant-expression
142149
<clang-tidy/checks/misc/redundant-expression>` check by providing additional

0 commit comments

Comments
 (0)