Skip to content

Commit bc049e4

Browse files
Merge remote-tracking branch 'intel_llvm/sycl' into multidim2
2 parents 7016d65 + a73369d commit bc049e4

File tree

2,027 files changed

+100419
-35216
lines changed

Some content is hidden

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

2,027 files changed

+100419
-35216
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ struct EqualClangTidyError {
744744
std::vector<ClangTidyError> ClangTidyDiagnosticConsumer::take() {
745745
finalizeLastError();
746746

747-
llvm::sort(Errors, LessClangTidyError());
747+
llvm::stable_sort(Errors, LessClangTidyError());
748748
Errors.erase(std::unique(Errors.begin(), Errors.end(), EqualClangTidyError()),
749749
Errors.end());
750750
if (RemoveIncompatibleErrors)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def write_implementation(module_path, module, namespace, check_name_camel):
136136
void %(check_name)s::check(const MatchFinder::MatchResult &Result) {
137137
// FIXME: Add callback implementation.
138138
const auto *MatchedDecl = Result.Nodes.getNodeAs<FunctionDecl>("x");
139-
if (MatchedDecl->getName().startswith("awesome_"))
139+
if (!MatchedDecl->getIdentifier() || MatchedDecl->getName().startswith("awesome_"))
140140
return;
141141
diag(MatchedDecl->getLocation(), "function %%0 is insufficiently awesome")
142142
<< MatchedDecl;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
3939
return llvm::None;
4040
const MacroInfo *MI = PP->getMacroInfo(It->first);
4141
const Token &T = MI->tokens().back();
42-
if (!T.isLiteral())
42+
if (!T.isLiteral() || !T.getLiteralData())
4343
return llvm::None;
4444
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
4545

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,16 @@ void NotNullTerminatedResultCheck::check(
802802
while (It != PP->macro_end() && !AreSafeFunctionsWanted.hasValue()) {
803803
if (It->first->getName() == "__STDC_WANT_LIB_EXT1__") {
804804
const auto *MI = PP->getMacroInfo(It->first);
805-
const auto &T = MI->tokens().back();
806-
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
807-
llvm::APInt IntValue;
808-
ValueStr.getAsInteger(10, IntValue);
809-
AreSafeFunctionsWanted = IntValue.getZExtValue();
805+
// PP->getMacroInfo() returns nullptr if macro has no definition.
806+
if (MI) {
807+
const auto &T = MI->tokens().back();
808+
if (T.isLiteral() && T.getLiteralData()) {
809+
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
810+
llvm::APInt IntValue;
811+
ValueStr.getAsInteger(10, IntValue);
812+
AreSafeFunctionsWanted = IntValue.getZExtValue();
813+
}
814+
}
810815
}
811816

812817
++It;

clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,11 @@ AST_MATCHER_P(QualType, isSugarFor, Matcher<QualType>, SugarMatcher) {
119119
/// \endcode
120120
///
121121
/// namedDecl(hasStdIteratorName()) matches \c I and \c CI.
122-
AST_MATCHER(NamedDecl, hasStdIteratorName) {
123-
static const char *const IteratorNames[] = {"iterator", "reverse_iterator",
124-
"const_iterator",
125-
"const_reverse_iterator"};
126-
127-
for (const char *Name : IteratorNames) {
128-
if (hasName(Name).matches(Node, Finder, Builder))
129-
return true;
130-
}
131-
return false;
122+
Matcher<NamedDecl> hasStdIteratorName() {
123+
static const StringRef IteratorNames[] = {"iterator", "reverse_iterator",
124+
"const_iterator",
125+
"const_reverse_iterator"};
126+
return hasAnyName(IteratorNames);
132127
}
133128

134129
/// Matches named declarations that have one of the standard container
@@ -143,26 +138,21 @@ AST_MATCHER(NamedDecl, hasStdIteratorName) {
143138
///
144139
/// recordDecl(hasStdContainerName()) matches \c vector and \c forward_list
145140
/// but not \c my_vec.
146-
AST_MATCHER(NamedDecl, hasStdContainerName) {
147-
static const char *const ContainerNames[] = {
148-
"array", "deque",
149-
"forward_list", "list",
150-
"vector",
141+
Matcher<NamedDecl> hasStdContainerName() {
142+
static StringRef ContainerNames[] = {"array", "deque",
143+
"forward_list", "list",
144+
"vector",
151145

152-
"map", "multimap",
153-
"set", "multiset",
146+
"map", "multimap",
147+
"set", "multiset",
154148

155-
"unordered_map", "unordered_multimap",
156-
"unordered_set", "unordered_multiset",
149+
"unordered_map", "unordered_multimap",
150+
"unordered_set", "unordered_multiset",
157151

158-
"queue", "priority_queue",
159-
"stack"};
152+
"queue", "priority_queue",
153+
"stack"};
160154

161-
for (const char *Name : ContainerNames) {
162-
if (hasName(Name).matches(Node, Finder, Builder))
163-
return true;
164-
}
165-
return false;
155+
return hasAnyName(ContainerNames);
166156
}
167157

168158
/// Matches declarations whose declaration context is the C++ standard library

clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,7 @@ TransformerClangTidyCheck::TransformerClangTidyCheck(RewriteRule R,
5353

5454
void TransformerClangTidyCheck::registerPPCallbacks(
5555
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
56-
// Only register the IncludeInsert when some `Case` will add
57-
// includes.
58-
if (Rule && llvm::any_of(Rule->Cases, [](const RewriteRule::Case &C) {
59-
return !C.AddedIncludes.empty();
60-
}))
61-
Inserter.registerPreprocessor(PP);
56+
Inserter.registerPreprocessor(PP);
6257
}
6358

6459
void TransformerClangTidyCheck::registerMatchers(
@@ -96,13 +91,19 @@ void TransformerClangTidyCheck::check(
9691
// Associate the diagnostic with the location of the first change.
9792
DiagnosticBuilder Diag = diag((*Edits)[0].Range.getBegin(), *Explanation);
9893
for (const auto &T : *Edits)
99-
Diag << FixItHint::CreateReplacement(T.Range, T.Replacement);
100-
101-
for (const auto &I : Case.AddedIncludes) {
102-
Diag << Inserter.createMainFileIncludeInsertion(
103-
I.first,
104-
/*IsAngled=*/I.second == transformer::IncludeFormat::Angled);
105-
}
94+
switch (T.Kind) {
95+
case transformer::EditKind::Range:
96+
Diag << FixItHint::CreateReplacement(T.Range, T.Replacement);
97+
break;
98+
case transformer::EditKind::AddInclude: {
99+
StringRef FileName = T.Replacement;
100+
bool IsAngled = FileName.startswith("<") && FileName.endswith(">");
101+
Diag << Inserter.createMainFileIncludeInsertion(
102+
IsAngled ? FileName.substr(1, FileName.size() - 2) : FileName,
103+
IsAngled);
104+
break;
105+
}
106+
}
106107
}
107108

108109
void TransformerClangTidyCheck::storeOptions(

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,8 +1617,10 @@ class CodeCompleteFlow {
16171617

16181618
llvm::Optional<float> fuzzyScore(const CompletionCandidate &C) {
16191619
// Macros can be very spammy, so we only support prefix completion.
1620-
// We won't end up with underfull index results, as macros are sema-only.
1621-
if (C.SemaResult && C.SemaResult->Kind == CodeCompletionResult::RK_Macro &&
1620+
if (((C.SemaResult &&
1621+
C.SemaResult->Kind == CodeCompletionResult::RK_Macro) ||
1622+
(C.IndexResult &&
1623+
C.IndexResult->SymInfo.Kind == index::SymbolKind::Macro)) &&
16221624
!C.Name.startswith_lower(Filter->pattern()))
16231625
return None;
16241626
return Filter->match(C.Name);

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,21 @@ struct TargetFinder {
355355
Flags |= Rel::Underlying; // continue with the underlying decl.
356356
} else if (const auto *DG = dyn_cast<CXXDeductionGuideDecl>(D)) {
357357
D = DG->getDeducedTemplate();
358+
} else if (const ObjCImplementationDecl *IID =
359+
dyn_cast<ObjCImplementationDecl>(D)) {
360+
// Treat ObjC{Interface,Implementation}Decl as if they were a decl/def
361+
// pair as long as the interface isn't implicit.
362+
if (const auto *CID = IID->getClassInterface())
363+
if (const auto *DD = CID->getDefinition())
364+
if (!DD->isImplicitInterfaceDecl())
365+
D = DD;
366+
} else if (const ObjCCategoryImplDecl *CID =
367+
dyn_cast<ObjCCategoryImplDecl>(D)) {
368+
// Treat ObjC{Category,CategoryImpl}Decl as if they were a decl/def pair.
369+
D = CID->getCategoryDecl();
358370
}
371+
if (!D)
372+
return;
359373

360374
if (const Decl *Pat = getTemplatePattern(D)) {
361375
assert(Pat != D);
@@ -596,6 +610,19 @@ struct TargetFinder {
596610
add(CCI->getAnyMember(), Flags);
597611
// Constructor calls contain a TypeLoc node, so we don't handle them here.
598612
}
613+
614+
void add(const TemplateArgument &Arg, RelSet Flags) {
615+
// Only used for template template arguments.
616+
// For type and non-type template arguments, SelectionTree
617+
// will hit a more specific node (e.g. a TypeLoc or a
618+
// DeclRefExpr).
619+
if (Arg.getKind() == TemplateArgument::Template ||
620+
Arg.getKind() == TemplateArgument::TemplateExpansion) {
621+
if (TemplateDecl *TD = Arg.getAsTemplate().getAsTemplateDecl()) {
622+
report(TD, Flags);
623+
}
624+
}
625+
}
599626
};
600627

601628
} // namespace
@@ -619,6 +646,8 @@ allTargetDecls(const ast_type_traits::DynTypedNode &N) {
619646
Finder.add(*QT, Flags);
620647
else if (const CXXCtorInitializer *CCI = N.get<CXXCtorInitializer>())
621648
Finder.add(CCI, Flags);
649+
else if (const TemplateArgumentLoc *TAL = N.get<TemplateArgumentLoc>())
650+
Finder.add(TAL->getArgument(), Flags);
622651

623652
return Finder.takeDecls();
624653
}

clang-tools-extra/clangd/ParsedAST.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class ParsedAST {
131131
std::unique_ptr<FrontendAction> Action;
132132
/// Tokens recorded after the preamble finished.
133133
/// - Includes all spelled tokens for the main file.
134-
/// - Includes expanded tokens produced **after** preabmle.
134+
/// - Includes expanded tokens produced **after** preamble.
135135
/// - Does not have spelled or expanded tokens for files from preamble.
136136
syntax::TokenBuffer Tokens;
137137

clang-tools-extra/clangd/RIFF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ llvm::Expected<Chunk> readChunk(llvm::StringRef &Stream) {
3333
llvm::Twine(Stream.size()));
3434
C.Data = Stream.take_front(Len);
3535
Stream = Stream.drop_front(Len);
36-
if (Len % 2 & !Stream.empty()) { // Skip padding byte.
36+
if ((Len % 2) && !Stream.empty()) { // Skip padding byte.
3737
if (Stream.front())
3838
return makeError("nonzero padding byte");
3939
Stream = Stream.drop_front();

clang-tools-extra/clangd/Selection.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ class SelectionVisitor : public RecursiveASTVisitor<SelectionVisitor> {
479479
bool TraverseTypeLoc(TypeLoc X) {
480480
return traverseNode(&X, [&] { return Base::TraverseTypeLoc(X); });
481481
}
482+
bool TraverseTemplateArgumentLoc(const TemplateArgumentLoc &X) {
483+
return traverseNode(&X,
484+
[&] { return Base::TraverseTemplateArgumentLoc(X); });
485+
}
482486
bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc X) {
483487
return traverseNode(
484488
&X, [&] { return Base::TraverseNestedNameSpecifierLoc(X); });

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ llvm::Optional<HighlightingKind> kindForDecl(const NamedDecl *D) {
9090
? HighlightingKind::StaticField
9191
: VD->isLocalVarDecl() ? HighlightingKind::LocalVariable
9292
: HighlightingKind::Variable;
93-
if (isa<BindingDecl>(D))
94-
return HighlightingKind::Variable;
93+
if (const auto *BD = dyn_cast<BindingDecl>(D))
94+
return BD->getDeclContext()->isFunctionOrMethod()
95+
? HighlightingKind::LocalVariable
96+
: HighlightingKind::Variable;
9597
if (isa<FunctionDecl>(D))
9698
return HighlightingKind::Function;
9799
if (isa<NamespaceDecl>(D) || isa<NamespaceAliasDecl>(D) ||
@@ -296,6 +298,18 @@ class CollectExtraHighlightings
296298
return true;
297299
}
298300

301+
bool TraverseTemplateArgumentLoc(TemplateArgumentLoc L) {
302+
switch (L.getArgument().getKind()) {
303+
case TemplateArgument::Template:
304+
case TemplateArgument::TemplateExpansion:
305+
H.addToken(L.getTemplateNameLoc(), HighlightingKind::DependentType);
306+
break;
307+
default:
308+
break;
309+
}
310+
return RecursiveASTVisitor::TraverseTemplateArgumentLoc(L);
311+
}
312+
299313
// findExplicitReferences will walk nested-name-specifiers and
300314
// find anything that can be resolved to a Decl. However, non-leaf
301315
// components of nested-name-specifiers which are dependent names

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,32 @@ const NamedDecl *getDefinition(const NamedDecl *D) {
7878
return VD->getDefinition();
7979
if (const auto *FD = dyn_cast<FunctionDecl>(D))
8080
return FD->getDefinition();
81+
// Objective-C classes can have three types of declarations:
82+
//
83+
// - forward declaration: @class MyClass;
84+
// - true declaration (interface definition): @interface MyClass ... @end
85+
// - true definition (implementation): @implementation MyClass ... @end
86+
//
87+
// Objective-C categories are extensions are on classes:
88+
//
89+
// - declaration: @interface MyClass (Ext) ... @end
90+
// - definition: @implementation MyClass (Ext) ... @end
91+
//
92+
// With one special case, a class extension, which is normally used to keep
93+
// some declarations internal to a file without exposing them in a header.
94+
//
95+
// - class extension declaration: @interface MyClass () ... @end
96+
// - which really links to class definition: @implementation MyClass ... @end
97+
if (const auto *ID = dyn_cast<ObjCInterfaceDecl>(D))
98+
return ID->getImplementation();
99+
if (const auto *CD = dyn_cast<ObjCCategoryDecl>(D)) {
100+
if (CD->IsClassExtension()) {
101+
if (const auto *ID = CD->getClassInterface())
102+
return ID->getImplementation();
103+
return nullptr;
104+
}
105+
return CD->getImplementation();
106+
}
81107
// Only a single declaration is allowed.
82108
if (isa<ValueDecl>(D) || isa<TemplateTypeParmDecl>(D) ||
83109
isa<TemplateTemplateParmDecl>(D)) // except cases above
@@ -223,6 +249,37 @@ locateMacroReferent(const syntax::Token &TouchedIdentifier, ParsedAST &AST,
223249
return llvm::None;
224250
}
225251

252+
// A wrapper around `Decl::getCanonicalDecl` to support cases where Clang's
253+
// definition of a canonical declaration doesn't match up to what a programmer
254+
// would expect. For example, Objective-C classes can have three types of
255+
// declarations:
256+
//
257+
// - forward declaration(s): @class MyClass;
258+
// - true declaration (interface definition): @interface MyClass ... @end
259+
// - true definition (implementation): @implementation MyClass ... @end
260+
//
261+
// Clang will consider the forward declaration to be the canonical declaration
262+
// because it is first. We actually want the class definition if it is
263+
// available since that is what a programmer would consider the primary
264+
// declaration to be.
265+
const NamedDecl *getPreferredDecl(const NamedDecl *D) {
266+
// FIXME: Canonical declarations of some symbols might refer to built-in
267+
// decls with possibly-invalid source locations (e.g. global new operator).
268+
// In such cases we should pick up a redecl with valid source location
269+
// instead of failing.
270+
D = llvm::cast<NamedDecl>(D->getCanonicalDecl());
271+
272+
// Prefer Objective-C class/protocol definitions over the forward declaration.
273+
if (const auto *ID = dyn_cast<ObjCInterfaceDecl>(D))
274+
if (const auto *DefinitionID = ID->getDefinition())
275+
return DefinitionID;
276+
if (const auto *PD = dyn_cast<ObjCProtocolDecl>(D))
277+
if (const auto *DefinitionID = PD->getDefinition())
278+
return DefinitionID;
279+
280+
return D;
281+
}
282+
226283
// Decls are more complicated.
227284
// The AST contains at least a declaration, maybe a definition.
228285
// These are up-to-date, and so generally preferred over index results.
@@ -238,11 +295,7 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
238295
llvm::DenseMap<SymbolID, size_t> ResultIndex;
239296

240297
auto AddResultDecl = [&](const NamedDecl *D) {
241-
// FIXME: Canonical declarations of some symbols might refer to built-in
242-
// decls with possibly-invalid source locations (e.g. global new operator).
243-
// In such cases we should pick up a redecl with valid source location
244-
// instead of failing.
245-
D = llvm::cast<NamedDecl>(D->getCanonicalDecl());
298+
D = getPreferredDecl(D);
246299
auto Loc =
247300
makeLocation(AST.getASTContext(), nameLocation(*D, SM), MainFilePath);
248301
if (!Loc)
@@ -290,6 +343,31 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
290343
}
291344
}
292345

346+
// Give the underlying decl if navigation is triggered on a non-renaming
347+
// alias.
348+
if (llvm::isa<UsingDecl>(D)) {
349+
// FIXME: address more complicated cases. TargetDecl(... Underlying) gives
350+
// all overload candidates, we only want the targeted one if the cursor is
351+
// on an using-alias usage, workround it with getDeclAtPosition.
352+
llvm::for_each(
353+
getDeclAtPosition(AST, CurLoc, DeclRelation::Underlying, NodeKind),
354+
[&](const NamedDecl *UD) { AddResultDecl(UD); });
355+
continue;
356+
}
357+
358+
// Special case: if the class name is selected, also map Objective-C
359+
// categories and category implementations back to their class interface.
360+
//
361+
// Since `TouchedIdentifier` might refer to the `ObjCCategoryImplDecl`
362+
// instead of the `ObjCCategoryDecl` we intentionally check the contents
363+
// of the locs when checking for class name equivalence.
364+
if (const auto *CD = dyn_cast<ObjCCategoryDecl>(D))
365+
if (const auto *ID = CD->getClassInterface())
366+
if (TouchedIdentifier &&
367+
(CD->getLocation() == TouchedIdentifier->location() ||
368+
ID->getName() == TouchedIdentifier->text(SM)))
369+
AddResultDecl(ID);
370+
293371
// Otherwise the target declaration is the right one.
294372
AddResultDecl(D);
295373
}

0 commit comments

Comments
 (0)