Skip to content

Commit b257bf9

Browse files
author
iclsrc
committed
Merge from 'master' to 'sycl-web'
2 parents 918d599 + ae920a8 commit b257bf9

File tree

961 files changed

+51177
-6050
lines changed

Some content is hidden

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

961 files changed

+51177
-6050
lines changed

clang-tools-extra/clang-tidy/add_new_check.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
172172
lines = iter(lines)
173173
try:
174174
while True:
175-
line = lines.next()
175+
line = next(lines)
176176
if not header_added:
177177
match = re.search('#include "(.*)"', line)
178178
if match:
@@ -197,7 +197,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
197197
# If we didn't find the check name on this line, look on the
198198
# next one.
199199
prev_line = line
200-
line = lines.next()
200+
line = next(lines)
201201
match = re.search(' *"([^"]*)"', line)
202202
if match:
203203
current_check_name = match.group(1)

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ using namespace clang::ast_matchers;
1919
namespace clang {
2020
namespace tidy {
2121
namespace bugprone {
22+
namespace {
23+
AST_MATCHER(Decl, isFromStdNamespace) {
24+
if (const auto *D = Node.getDeclContext()->getEnclosingNamespaceContext())
25+
return D->isStdNamespace();
26+
return false;
27+
}
28+
} // namespace
2229

2330
ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name,
2431
ClangTidyContext *Context)
@@ -54,10 +61,18 @@ void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
5461
// don't check them against NewCallback's parameter names.
5562
// FIXME: Make this configurable.
5663
unless(hasDeclaration(functionDecl(
57-
hasAnyName("NewCallback", "NewPermanentCallback")))))
64+
hasAnyName("NewCallback", "NewPermanentCallback")))),
65+
// Ignore APIs from the standard library, since their names are
66+
// not specified by the standard, and standard library
67+
// implementations in practice have to use reserved names to
68+
// avoid conflicts with same-named macros.
69+
unless(hasDeclaration(isFromStdNamespace())))
70+
.bind("expr"),
71+
this);
72+
Finder->addMatcher(
73+
cxxConstructExpr(unless(hasDeclaration(isFromStdNamespace())))
5874
.bind("expr"),
5975
this);
60-
Finder->addMatcher(cxxConstructExpr().bind("expr"), this);
6176
}
6277

6378
static std::vector<std::pair<SourceLocation, StringRef>>

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ static Matcher<TypedefDecl> hasAnyListedName(const std::string &Names) {
2929
SignedCharMisuseCheck::SignedCharMisuseCheck(StringRef Name,
3030
ClangTidyContext *Context)
3131
: ClangTidyCheck(Name, Context),
32-
CharTypdefsToIgnoreList(Options.get("CharTypdefsToIgnore", "")) {}
32+
CharTypdefsToIgnoreList(Options.get("CharTypdefsToIgnore", "")),
33+
DiagnoseSignedUnsignedCharComparisons(
34+
Options.get("DiagnoseSignedUnsignedCharComparisons", true)) {}
3335

3436
void SignedCharMisuseCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
3537
Options.store(Opts, "CharTypdefsToIgnore", CharTypdefsToIgnoreList);
38+
Options.store(Opts, "DiagnoseSignedUnsignedCharComparisons",
39+
DiagnoseSignedUnsignedCharComparisons);
3640
}
3741

3842
// Create a matcher for char -> integer cast.
@@ -92,16 +96,18 @@ void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {
9296

9397
Finder->addMatcher(Declaration, this);
9498

95-
// Catch signed char/unsigned char comparison.
96-
const auto CompareOperator =
97-
expr(binaryOperator(hasAnyOperatorName("==", "!="),
98-
anyOf(allOf(hasLHS(SignedCharCastExpr),
99-
hasRHS(UnSignedCharCastExpr)),
100-
allOf(hasLHS(UnSignedCharCastExpr),
101-
hasRHS(SignedCharCastExpr)))))
102-
.bind("comparison");
103-
104-
Finder->addMatcher(CompareOperator, this);
99+
if (DiagnoseSignedUnsignedCharComparisons) {
100+
// Catch signed char/unsigned char comparison.
101+
const auto CompareOperator =
102+
expr(binaryOperator(hasAnyOperatorName("==", "!="),
103+
anyOf(allOf(hasLHS(SignedCharCastExpr),
104+
hasRHS(UnSignedCharCastExpr)),
105+
allOf(hasLHS(UnSignedCharCastExpr),
106+
hasRHS(SignedCharCastExpr)))))
107+
.bind("comparison");
108+
109+
Finder->addMatcher(CompareOperator, this);
110+
}
105111

106112
// Catch array subscripts with signed char -> integer conversion.
107113
// Matcher for C arrays.

clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SignedCharMisuseCheck : public ClangTidyCheck {
3838
const std::string &CastBindName) const;
3939

4040
const std::string CharTypdefsToIgnoreList;
41+
const bool DiagnoseSignedUnsignedCharComparisons;
4142
};
4243

4344
} // namespace bugprone

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "../ClangTidyModuleRegistry.h"
1212
#include "../bugprone/BadSignalToKillThreadCheck.h"
1313
#include "../bugprone/ReservedIdentifierCheck.h"
14+
#include "../bugprone/SignedCharMisuseCheck.h"
1415
#include "../bugprone/SpuriouslyWakeUpFunctionsCheck.h"
1516
#include "../bugprone/UnhandledSelfAssignmentCheck.h"
1617
#include "../google/UnnamedNamespaceInHeaderCheck.h"
@@ -108,13 +109,17 @@ class CERTModule : public ClangTidyModule {
108109
// POS
109110
CheckFactories.registerCheck<bugprone::BadSignalToKillThreadCheck>(
110111
"cert-pos44-c");
112+
// STR
113+
CheckFactories.registerCheck<bugprone::SignedCharMisuseCheck>(
114+
"cert-str34-c");
111115
}
112116

113117
ClangTidyOptions getModuleOptions() override {
114118
ClangTidyOptions Options;
115119
ClangTidyOptions::OptionMap &Opts = Options.CheckOptions;
116120
Opts["cert-dcl16-c.NewSuffixes"] = "L;LL;LU;LLU";
117121
Opts["cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField"] = "0";
122+
Opts["cert-str34-c.DiagnoseSignedUnsignedCharComparisons"] = "0";
118123
return Options;
119124
}
120125
};

clang-tools-extra/clang-tidy/performance/ForRangeCopyCheck.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,18 @@ void ForRangeCopyCheck::registerMatchers(MatchFinder *Finder) {
3737
// Match loop variables that are not references or pointers or are already
3838
// initialized through MaterializeTemporaryExpr which indicates a type
3939
// conversion.
40-
auto LoopVar = varDecl(
41-
hasType(qualType(
42-
unless(anyOf(hasCanonicalType(anyOf(referenceType(), pointerType())),
43-
hasDeclaration(namedDecl(
44-
matchers::matchesAnyListedName(AllowedTypes))))))),
45-
unless(hasInitializer(expr(hasDescendant(materializeTemporaryExpr())))));
40+
auto HasReferenceOrPointerTypeOrIsAllowed = hasType(qualType(
41+
unless(anyOf(hasCanonicalType(anyOf(referenceType(), pointerType())),
42+
hasDeclaration(namedDecl(
43+
matchers::matchesAnyListedName(AllowedTypes)))))));
44+
auto IteratorReturnsValueType = cxxOperatorCallExpr(
45+
hasOverloadedOperatorName("*"),
46+
callee(
47+
cxxMethodDecl(returns(unless(hasCanonicalType(referenceType()))))));
48+
auto LoopVar =
49+
varDecl(HasReferenceOrPointerTypeOrIsAllowed,
50+
unless(hasInitializer(expr(hasDescendant(expr(anyOf(
51+
materializeTemporaryExpr(), IteratorReturnsValueType)))))));
4652
Finder->addMatcher(cxxForRangeStmt(hasLoopVariable(LoopVar.bind("loopVar")))
4753
.bind("forRange"),
4854
this);

clang-tools-extra/clangd/Headers.cpp

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "Compiler.h"
1111
#include "SourceCode.h"
1212
#include "support/Logger.h"
13+
#include "clang/Basic/SourceLocation.h"
14+
#include "clang/Basic/SourceManager.h"
1315
#include "clang/Frontend/CompilerInstance.h"
1416
#include "clang/Frontend/CompilerInvocation.h"
1517
#include "clang/Frontend/FrontendActions.h"
@@ -21,6 +23,11 @@ namespace clang {
2123
namespace clangd {
2224
namespace {
2325

26+
bool isMainFile(llvm::StringRef FileName, const SourceManager &SM) {
27+
auto FE = SM.getFileManager().getFile(FileName);
28+
return FE && *FE == SM.getFileEntryForID(SM.getMainFileID());
29+
}
30+
2431
class RecordHeaders : public PPCallbacks {
2532
public:
2633
RecordHeaders(const SourceManager &SM, IncludeStructure *Out)
@@ -30,11 +37,27 @@ class RecordHeaders : public PPCallbacks {
3037
// in the main file are collected.
3138
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
3239
llvm::StringRef FileName, bool IsAngled,
33-
CharSourceRange FilenameRange, const FileEntry *File,
34-
llvm::StringRef /*SearchPath*/,
40+
CharSourceRange /*FilenameRange*/,
41+
const FileEntry *File, llvm::StringRef /*SearchPath*/,
3542
llvm::StringRef /*RelativePath*/,
3643
const Module * /*Imported*/,
3744
SrcMgr::CharacteristicKind FileKind) override {
45+
auto MainFID = SM.getMainFileID();
46+
// If an include is part of the preamble patch, translate #line directives.
47+
if (InBuiltinFile) {
48+
auto Presumed = SM.getPresumedLoc(HashLoc);
49+
// Presumed locations will have an invalid file id when #line directive
50+
// changes the filename.
51+
if (Presumed.getFileID().isInvalid() &&
52+
isMainFile(Presumed.getFilename(), SM)) {
53+
// Now we'll hit the case below.
54+
HashLoc = SM.translateLineCol(MainFID, Presumed.getLine(),
55+
Presumed.getColumn());
56+
}
57+
}
58+
59+
// Record main-file inclusions (including those mapped from the preamble
60+
// patch).
3861
if (isInsideMainFile(HashLoc, SM)) {
3962
Out->MainFileIncludes.emplace_back();
4063
auto &Inc = Out->MainFileIncludes.back();
@@ -47,21 +70,48 @@ class RecordHeaders : public PPCallbacks {
4770
Inc.FileKind = FileKind;
4871
Inc.Directive = IncludeTok.getIdentifierInfo()->getPPKeywordID();
4972
}
73+
74+
// Record include graph (not just for main-file includes)
5075
if (File) {
5176
auto *IncludingFileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc));
5277
if (!IncludingFileEntry) {
5378
assert(SM.getBufferName(HashLoc).startswith("<") &&
5479
"Expected #include location to be a file or <built-in>");
5580
// Treat as if included from the main file.
56-
IncludingFileEntry = SM.getFileEntryForID(SM.getMainFileID());
81+
IncludingFileEntry = SM.getFileEntryForID(MainFID);
5782
}
5883
Out->recordInclude(IncludingFileEntry->getName(), File->getName(),
5984
File->tryGetRealPathName());
6085
}
6186
}
6287

88+
void FileChanged(SourceLocation Loc, FileChangeReason Reason,
89+
SrcMgr::CharacteristicKind FileType,
90+
FileID PrevFID) override {
91+
switch (Reason) {
92+
case PPCallbacks::EnterFile:
93+
if (BuiltinFile.isInvalid() && SM.isWrittenInBuiltinFile(Loc)) {
94+
BuiltinFile = SM.getFileID(Loc);
95+
InBuiltinFile = true;
96+
}
97+
break;
98+
case PPCallbacks::ExitFile:
99+
if (PrevFID == BuiltinFile)
100+
InBuiltinFile = false;
101+
break;
102+
case PPCallbacks::RenameFile:
103+
case PPCallbacks::SystemHeaderPragma:
104+
break;
105+
}
106+
}
107+
63108
private:
64109
const SourceManager &SM;
110+
// Set after entering the <built-in> file.
111+
FileID BuiltinFile;
112+
// Indicates whether <built-in> file is part of include stack.
113+
bool InBuiltinFile = false;
114+
65115
IncludeStructure *Out;
66116
};
67117

@@ -233,5 +283,11 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const Inclusion &Inc) {
233283
<< " at line" << Inc.HashLine;
234284
}
235285

286+
bool operator==(const Inclusion &LHS, const Inclusion &RHS) {
287+
return std::tie(LHS.Directive, LHS.FileKind, LHS.HashOffset, LHS.HashLine,
288+
LHS.Resolved, LHS.Written) ==
289+
std::tie(RHS.Directive, RHS.FileKind, RHS.HashOffset, RHS.HashLine,
290+
RHS.Resolved, RHS.Written);
291+
}
236292
} // namespace clangd
237293
} // namespace clang

clang-tools-extra/clangd/Headers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct Inclusion {
6060
SrcMgr::CharacteristicKind FileKind = SrcMgr::C_User;
6161
};
6262
llvm::raw_ostream &operator<<(llvm::raw_ostream &, const Inclusion &);
63+
bool operator==(const Inclusion &LHS, const Inclusion &RHS);
6364

6465
// Contains information about one file in the build grpah and its direct
6566
// dependencies. Doesn't own the strings it references (IncludeGraph is

clang-tools-extra/clangd/Preamble.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Preamble.h"
1010
#include "Compiler.h"
1111
#include "Headers.h"
12+
#include "SourceCode.h"
1213
#include "support/Logger.h"
1314
#include "support/Trace.h"
1415
#include "clang/Basic/Diagnostic.h"
@@ -26,6 +27,7 @@
2627
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2728
#include "llvm/ADT/STLExtras.h"
2829
#include "llvm/ADT/SmallString.h"
30+
#include "llvm/ADT/StringExtras.h"
2931
#include "llvm/ADT/StringRef.h"
3032
#include "llvm/ADT/StringSet.h"
3133
#include "llvm/Support/Error.h"
@@ -270,6 +272,20 @@ bool isPreambleCompatible(const PreambleData &Preamble,
270272
Inputs.FS.get());
271273
}
272274

275+
void escapeBackslashAndQuotes(llvm::StringRef Text, llvm::raw_ostream &OS) {
276+
for (char C : Text) {
277+
switch (C) {
278+
case '\\':
279+
case '"':
280+
OS << '\\';
281+
break;
282+
default:
283+
break;
284+
}
285+
OS << C;
286+
}
287+
}
288+
273289
PreamblePatch PreamblePatch::create(llvm::StringRef FileName,
274290
const ParseInputs &Modified,
275291
const PreambleData &Baseline) {
@@ -298,6 +314,9 @@ PreamblePatch PreamblePatch::create(llvm::StringRef FileName,
298314
ModifiedIncludes.takeError());
299315
return {};
300316
}
317+
// No patch needed if includes are equal.
318+
if (*BaselineIncludes == *ModifiedIncludes)
319+
return {};
301320

302321
PreamblePatch PP;
303322
// This shouldn't coincide with any real file name.
@@ -314,9 +333,19 @@ PreamblePatch PreamblePatch::create(llvm::StringRef FileName,
314333
ExistingIncludes.insert({Inc.Directive, Inc.Written});
315334
// Calculate extra includes that needs to be inserted.
316335
llvm::raw_string_ostream Patch(PP.PatchContents);
336+
// Set default filename for subsequent #line directives
337+
Patch << "#line 0 \"";
338+
// FileName part of a line directive is subject to backslash escaping, which
339+
// might lead to problems on windows especially.
340+
escapeBackslashAndQuotes(FileName, Patch);
341+
Patch << "\"\n";
317342
for (const auto &Inc : *ModifiedIncludes) {
318343
if (ExistingIncludes.count({Inc.Directive, Inc.Written}))
319344
continue;
345+
// Include is new in the modified preamble. Inject it into the patch and use
346+
// #line to set the presumed location to where it is spelled.
347+
auto LineCol = offsetToClangLineColumn(Modified.Contents, Inc.HashOffset);
348+
Patch << llvm::formatv("#line {0}\n", LineCol.first);
320349
Patch << llvm::formatv("#{0} {1}\n", spellingForIncDirective(Inc.Directive),
321350
Inc.Written);
322351
}

clang-tools-extra/clangd/index/remote/Client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <grpcpp/grpcpp.h>
9+
#include <grpc++/grpc++.h>
1010

1111
#include "Client.h"
1212
#include "Index.grpc.pb.h"

clang-tools-extra/clangd/index/remote/server/Server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include "llvm/Support/CommandLine.h"
1414
#include "llvm/Support/Signals.h"
1515

16-
#include <grpcpp/grpcpp.h>
17-
#include <grpcpp/health_check_service_interface.h>
16+
#include <grpc++/grpc++.h>
17+
#include <grpc++/health_check_service_interface.h>
1818

1919
#include "Index.grpc.pb.h"
2020

0 commit comments

Comments
 (0)