Skip to content

Commit 610e250

Browse files
committed
Merge from 'main' to 'sycl-web' (#100)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
2 parents 2aae9e9 + 2a2c228 commit 610e250

File tree

676 files changed

+40587
-19660
lines changed

Some content is hidden

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

676 files changed

+40587
-19660
lines changed

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ std::string UnparseableIntegerOptionError::message() const {
4242

4343
ClangTidyCheck::ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context)
4444
: CheckName(CheckName), Context(Context),
45-
Options(CheckName, Context->getOptions().CheckOptions) {
45+
Options(CheckName, Context->getOptions().CheckOptions, Context) {
4646
assert(Context != nullptr);
4747
assert(!CheckName.empty());
4848
}
@@ -52,16 +52,29 @@ DiagnosticBuilder ClangTidyCheck::diag(SourceLocation Loc, StringRef Message,
5252
return Context->diag(CheckName, Loc, Message, Level);
5353
}
5454

55+
DiagnosticBuilder ClangTidyCheck::diag(StringRef Message,
56+
DiagnosticIDs::Level Level) {
57+
return Context->diag(CheckName, Message, Level);
58+
}
59+
60+
DiagnosticBuilder
61+
ClangTidyCheck::configurationDiag(StringRef Description,
62+
DiagnosticIDs::Level Level) {
63+
return Context->configurationDiag(Description, Level);
64+
}
65+
5566
void ClangTidyCheck::run(const ast_matchers::MatchFinder::MatchResult &Result) {
5667
// For historical reasons, checks don't implement the MatchFinder run()
5768
// callback directly. We keep the run()/check() distinction to avoid interface
5869
// churn, and to allow us to add cross-cutting logic in the future.
5970
check(Result);
6071
}
6172

62-
ClangTidyCheck::OptionsView::OptionsView(StringRef CheckName,
63-
const ClangTidyOptions::OptionMap &CheckOptions)
64-
: NamePrefix(CheckName.str() + "."), CheckOptions(CheckOptions) {}
73+
ClangTidyCheck::OptionsView::OptionsView(
74+
StringRef CheckName, const ClangTidyOptions::OptionMap &CheckOptions,
75+
ClangTidyContext *Context)
76+
: NamePrefix(CheckName.str() + "."), CheckOptions(CheckOptions),
77+
Context(Context) {}
6578

6679
llvm::Expected<std::string>
6780
ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
@@ -121,7 +134,7 @@ bool ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName,
121134
llvm::Expected<bool> ValueOr = get<bool>(LocalName);
122135
if (ValueOr)
123136
return *ValueOr;
124-
logIfOptionParsingError(ValueOr.takeError());
137+
reportOptionParsingError(ValueOr.takeError());
125138
return Default;
126139
}
127140

@@ -140,7 +153,7 @@ bool ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName,
140153
llvm::Expected<bool> ValueOr = getLocalOrGlobal<bool>(LocalName);
141154
if (ValueOr)
142155
return *ValueOr;
143-
logIfOptionParsingError(ValueOr.takeError());
156+
reportOptionParsingError(ValueOr.takeError());
144157
return Default;
145158
}
146159

@@ -199,11 +212,11 @@ llvm::Expected<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
199212
Iter->getValue().Value);
200213
}
201214

202-
void ClangTidyCheck::OptionsView::logIfOptionParsingError(llvm::Error &&Err) {
215+
void ClangTidyCheck::OptionsView::reportOptionParsingError(
216+
llvm::Error &&Err) const {
203217
if (auto RemainingErrors =
204218
llvm::handleErrors(std::move(Err), [](const MissingOptionError &) {}))
205-
llvm::logAllUnhandledErrors(std::move(RemainingErrors),
206-
llvm::WithColor::warning());
219+
Context->configurationDiag(llvm::toString(std::move(RemainingErrors)));
207220
}
208221

209222
template <>

clang-tools-extra/clang-tidy/ClangTidyCheck.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,15 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
176176
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description,
177177
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
178178

179+
/// Add a diagnostic with the check's name.
180+
DiagnosticBuilder diag(StringRef Description,
181+
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
182+
183+
/// Adds a diagnostic to report errors in the check's configuration.
184+
DiagnosticBuilder
185+
configurationDiag(StringRef Description,
186+
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
187+
179188
/// Should store all options supported by this check with their
180189
/// current values or default values for options that haven't been overridden.
181190
///
@@ -192,7 +201,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
192201
public:
193202
/// Initializes the instance using \p CheckName + "." as a prefix.
194203
OptionsView(StringRef CheckName,
195-
const ClangTidyOptions::OptionMap &CheckOptions);
204+
const ClangTidyOptions::OptionMap &CheckOptions,
205+
ClangTidyContext *Context);
196206

197207
/// Read a named option from the ``Context``.
198208
///
@@ -268,7 +278,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
268278
if (llvm::Expected<T> ValueOr = get<T>(LocalName))
269279
return *ValueOr;
270280
else
271-
logIfOptionParsingError(ValueOr.takeError());
281+
reportOptionParsingError(ValueOr.takeError());
272282
return Default;
273283
}
274284

@@ -314,7 +324,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
314324
if (llvm::Expected<T> ValueOr = getLocalOrGlobal<T>(LocalName))
315325
return *ValueOr;
316326
else
317-
logIfOptionParsingError(ValueOr.takeError());
327+
reportOptionParsingError(ValueOr.takeError());
318328
return Default;
319329
}
320330

@@ -353,7 +363,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
353363
if (auto ValueOr = get<T>(LocalName, IgnoreCase))
354364
return *ValueOr;
355365
else
356-
logIfOptionParsingError(ValueOr.takeError());
366+
reportOptionParsingError(ValueOr.takeError());
357367
return Default;
358368
}
359369

@@ -395,7 +405,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
395405
if (auto ValueOr = getLocalOrGlobal<T>(LocalName, IgnoreCase))
396406
return *ValueOr;
397407
else
398-
logIfOptionParsingError(ValueOr.takeError());
408+
reportOptionParsingError(ValueOr.takeError());
399409
return Default;
400410
}
401411

@@ -407,7 +417,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
407417
if (auto ValueOr = get<T>(LocalName))
408418
return *ValueOr;
409419
else
410-
logIfOptionParsingError(ValueOr.takeError());
420+
reportOptionParsingError(ValueOr.takeError());
411421
return llvm::None;
412422
}
413423

@@ -420,7 +430,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
420430
if (auto ValueOr = getLocalOrGlobal<T>(LocalName))
421431
return *ValueOr;
422432
else
423-
logIfOptionParsingError(ValueOr.takeError());
433+
reportOptionParsingError(ValueOr.takeError());
424434
return llvm::None;
425435
}
426436

@@ -481,11 +491,12 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
481491
void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
482492
int64_t Value) const;
483493

484-
/// Logs an Error to stderr if a \p Err is not a MissingOptionError.
485-
static void logIfOptionParsingError(llvm::Error &&Err);
494+
/// Emits a diagnostic if \p Err is not a MissingOptionError.
495+
void reportOptionParsingError(llvm::Error &&Err) const;
486496

487497
std::string NamePrefix;
488498
const ClangTidyOptions::OptionMap &CheckOptions;
499+
ClangTidyContext *Context;
489500
};
490501

491502
private:

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,21 @@ DiagnosticBuilder ClangTidyContext::diag(
177177
return DiagEngine->Report(Loc, ID);
178178
}
179179

180+
DiagnosticBuilder ClangTidyContext::diag(
181+
StringRef CheckName, StringRef Description,
182+
DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/) {
183+
unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID(
184+
Level, (Description + " [" + CheckName + "]").str());
185+
CheckNamesByDiagnosticID.try_emplace(ID, CheckName);
186+
return DiagEngine->Report(ID);
187+
}
188+
189+
DiagnosticBuilder ClangTidyContext::configurationDiag(
190+
StringRef Message,
191+
DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/) {
192+
return diag("clang-tidy-config", Message, Level);
193+
}
194+
180195
void ClangTidyContext::setSourceManager(SourceManager *SourceMgr) {
181196
DiagEngine->setSourceManager(SourceMgr);
182197
}
@@ -256,8 +271,10 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(
256271
void ClangTidyDiagnosticConsumer::finalizeLastError() {
257272
if (!Errors.empty()) {
258273
ClangTidyError &Error = Errors.back();
259-
if (!Context.isCheckEnabled(Error.DiagnosticName) &&
260-
Error.DiagLevel != ClangTidyError::Error) {
274+
if (Error.DiagnosticName == "clang-tidy-config") {
275+
// Never ignore these.
276+
} else if (!Context.isCheckEnabled(Error.DiagnosticName) &&
277+
Error.DiagLevel != ClangTidyError::Error) {
261278
++Context.Stats.ErrorsIgnoredCheckFilter;
262279
Errors.pop_back();
263280
} else if (!LastErrorRelatesToUserCode) {

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ class ClangTidyContext {
9696
StringRef Message,
9797
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
9898

99+
DiagnosticBuilder diag(StringRef CheckName, StringRef Message,
100+
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
101+
102+
/// Report any errors to do with reading the configuration using this method.
103+
DiagnosticBuilder
104+
configurationDiag(StringRef Message,
105+
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
106+
99107
/// Sets the \c SourceManager of the used \c DiagnosticsEngine.
100108
///
101109
/// This is called from the \c ClangTidyCheck base class.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ GlobList::GlobList(StringRef Globs) {
5252
} while (!Globs.empty());
5353
}
5454

55-
bool GlobList::contains(StringRef S) {
55+
bool GlobList::contains(StringRef S) const {
5656
// Iterating the container backwards as the last match determins if S is in
5757
// the list.
5858
for (const GlobListItem &Item : llvm::reverse(Items)) {

clang-tools-extra/clang-tidy/GlobList.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class GlobList {
3333

3434
/// Returns \c true if the pattern matches \p S. The result is the last
3535
/// matching glob's Positive flag.
36-
bool contains(StringRef S);
36+
bool contains(StringRef S) const;
3737

3838
private:
3939

clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ using ::clang::transformer::makeRule;
3131
using ::clang::transformer::node;
3232
using ::clang::transformer::RewriteRule;
3333

34+
AST_MATCHER(Type, isCharType) { return Node.isCharType(); }
35+
3436
static const char DefaultStringLikeClasses[] = "::std::basic_string;"
3537
"::std::basic_string_view;"
3638
"::absl::string_view";
@@ -58,13 +60,15 @@ MakeRule(const LangOptions &LangOpts,
5860
hasUnqualifiedDesugaredType(recordType(hasDeclaration(StringLikeClass)));
5961
auto CharStarType =
6062
hasUnqualifiedDesugaredType(pointerType(pointee(isAnyCharacter())));
63+
auto CharType = hasUnqualifiedDesugaredType(isCharType());
6164
auto StringNpos = declRefExpr(
6265
to(varDecl(hasName("npos"), hasDeclContext(StringLikeClass))));
6366
auto StringFind = cxxMemberCallExpr(
6467
callee(cxxMethodDecl(
6568
hasName("find"),
66-
hasParameter(0, parmVarDecl(anyOf(hasType(StringType),
67-
hasType(CharStarType)))))),
69+
hasParameter(
70+
0, parmVarDecl(anyOf(hasType(StringType), hasType(CharStarType),
71+
hasType(CharType)))))),
6872
on(hasType(StringType)), hasArgument(0, expr().bind("parameter_to_find")),
6973
anyOf(hasArgument(1, integerLiteral(equals(0))),
7074
hasArgument(1, cxxDefaultArgExpr())),

clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(StringRef Name,
3434
if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
3535
HeaderFileExtensions,
3636
utils::defaultFileExtensionDelimiters())) {
37-
llvm::errs() << "Invalid header file extension: "
38-
<< RawStringHeaderFileExtensions << "\n";
37+
this->configurationDiag("Invalid header file extension: '%0'")
38+
<< RawStringHeaderFileExtensions;
3939
}
4040
}
4141

clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ SuspiciousIncludeCheck::SuspiciousIncludeCheck(StringRef Name,
4646
if (!utils::parseFileExtensions(RawStringImplementationFileExtensions,
4747
ImplementationFileExtensions,
4848
utils::defaultFileExtensionDelimiters())) {
49-
llvm::errs() << "Invalid implementation file extension: "
50-
<< RawStringImplementationFileExtensions << "\n";
49+
this->configurationDiag("Invalid implementation file extension: '%0'")
50+
<< RawStringImplementationFileExtensions;
5151
}
5252

5353
if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
5454
HeaderFileExtensions,
5555
utils::defaultFileExtensionDelimiters())) {
56-
llvm::errs() << "Invalid header file extension: "
57-
<< RawStringHeaderFileExtensions << "\n";
56+
this->configurationDiag("Invalid header file extension: '%0'")
57+
<< RawStringHeaderFileExtensions;
5858
}
5959
}
6060

clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
4848
Finder->addMatcher(
4949
traverse(
5050
ast_type_traits::TK_AsIs,
51-
implicitCastExpr(hasImplicitDestinationType(builtinType()),
52-
hasSourceExpression(hasType(builtinType())),
51+
implicitCastExpr(hasImplicitDestinationType(
52+
hasUnqualifiedDesugaredType(builtinType())),
53+
hasSourceExpression(hasType(
54+
hasUnqualifiedDesugaredType(builtinType()))),
5355
unless(hasSourceExpression(IsCeilFloorCallExpr)),
5456
unless(hasParent(castExpr())),
5557
unless(isInTemplateInstantiation()))
@@ -58,16 +60,18 @@ void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
5860

5961
// Binary operators:
6062
// i += 0.5;
61-
Finder->addMatcher(binaryOperator(isAssignmentOperator(),
62-
hasLHS(expr(hasType(builtinType()))),
63-
hasRHS(expr(hasType(builtinType()))),
64-
unless(hasRHS(IsCeilFloorCallExpr)),
65-
unless(isInTemplateInstantiation()),
66-
// The `=` case generates an implicit cast
67-
// which is covered by the previous matcher.
68-
unless(hasOperatorName("=")))
69-
.bind("binary_op"),
70-
this);
63+
Finder->addMatcher(
64+
binaryOperator(
65+
isAssignmentOperator(),
66+
hasLHS(expr(hasType(hasUnqualifiedDesugaredType(builtinType())))),
67+
hasRHS(expr(hasType(hasUnqualifiedDesugaredType(builtinType())))),
68+
unless(hasRHS(IsCeilFloorCallExpr)),
69+
unless(isInTemplateInstantiation()),
70+
// The `=` case generates an implicit cast
71+
// which is covered by the previous matcher.
72+
unless(hasOperatorName("=")))
73+
.bind("binary_op"),
74+
this);
7175
}
7276

7377
static const BuiltinType *getBuiltinType(const Expr &E) {

0 commit comments

Comments
 (0)