Skip to content

Commit 8205e86

Browse files
committed
Merge from 'master' to 'sycl-web' (#6)
CONFLICT (content): Merge conflict in clang/lib/Driver/Driver.cpp
2 parents 8fd0c5d + 5ac9d18 commit 8205e86

File tree

806 files changed

+22455
-11329
lines changed

Some content is hidden

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

806 files changed

+22455
-11329
lines changed

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

+8-9
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ loopEndingStmt(internal::Matcher<Stmt> Internal) {
2424
callExpr(Internal, callee(functionDecl(isNoReturn())))));
2525
}
2626

27-
/// \brief Return whether `S` is a reference to the declaration of `Var`.
27+
/// Return whether `S` is a reference to the declaration of `Var`.
2828
static bool isAccessForVar(const Stmt *S, const VarDecl *Var) {
2929
if (const auto *DRE = dyn_cast<DeclRefExpr>(S))
3030
return DRE->getDecl() == Var;
3131

3232
return false;
3333
}
3434

35-
/// \brief Return whether `Var` has a pointer of reference in `S`.
35+
/// Return whether `Var` has a pointer or reference in `S`.
3636
static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
3737
if (const auto *DS = dyn_cast<DeclStmt>(S)) {
3838
for (const Decl *D : DS->getDeclGroup()) {
@@ -50,7 +50,7 @@ static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
5050
return false;
5151
}
5252

53-
/// \brief Return whether `Var` has a pointer of reference in `S`.
53+
/// Return whether `Var` has a pointer or reference in `S`.
5454
static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var) {
5555
if (isPtrOrReferenceForVar(S, Var))
5656
return true;
@@ -66,13 +66,13 @@ static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var) {
6666
return false;
6767
}
6868

69-
/// \brief Return whether `Var` has a pointer of reference in `Func`.
69+
/// Return whether `Var` has a pointer or reference in `Func`.
7070
static bool hasPtrOrReferenceInFunc(const FunctionDecl *Func,
7171
const VarDecl *Var) {
7272
return hasPtrOrReferenceInStmt(Func->getBody(), Var);
7373
}
7474

75-
/// \brief Return whether `Var` was changed in `LoopStmt`.
75+
/// Return whether `Var` was changed in `LoopStmt`.
7676
static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var,
7777
ASTContext *Context) {
7878
if (const auto *ForLoop = dyn_cast<ForStmt>(LoopStmt))
@@ -88,8 +88,7 @@ static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var,
8888
return ExprMutationAnalyzer(*LoopStmt, *Context).isMutated(Var);
8989
}
9090

91-
/// \brief Return whether `Cond` is a variable that is possibly changed in
92-
/// `LoopStmt`.
91+
/// Return whether `Cond` is a variable that is possibly changed in `LoopStmt`.
9392
static bool isVarThatIsPossiblyChanged(const FunctionDecl *Func,
9493
const Stmt *LoopStmt, const Stmt *Cond,
9594
ASTContext *Context) {
@@ -116,7 +115,7 @@ static bool isVarThatIsPossiblyChanged(const FunctionDecl *Func,
116115
return false;
117116
}
118117

119-
/// \brief Return whether at least one variable of `Cond` changed in `LoopStmt`.
118+
/// Return whether at least one variable of `Cond` changed in `LoopStmt`.
120119
static bool isAtLeastOneCondVarChanged(const FunctionDecl *Func,
121120
const Stmt *LoopStmt, const Stmt *Cond,
122121
ASTContext *Context) {
@@ -133,7 +132,7 @@ static bool isAtLeastOneCondVarChanged(const FunctionDecl *Func,
133132
return false;
134133
}
135134

136-
/// \brief Return the variable names in `Cond`.
135+
/// Return the variable names in `Cond`.
137136
static std::string getCondVarNames(const Stmt *Cond) {
138137
if (const auto *DRE = dyn_cast<DeclRefExpr>(Cond)) {
139138
if (const auto *Var = dyn_cast<VarDecl>(DRE->getDecl()))

clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
33
add_clang_library(clangTidyCppCoreGuidelinesModule
44
AvoidGotoCheck.cpp
55
CppCoreGuidelinesTidyModule.cpp
6+
InitVariablesCheck.cpp
67
InterfacesGlobalInitCheck.cpp
78
MacroUsageCheck.cpp
89
NarrowingConversionsCheck.cpp

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

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "../modernize/UseOverrideCheck.h"
1616
#include "../readability/MagicNumbersCheck.h"
1717
#include "AvoidGotoCheck.h"
18+
#include "InitVariablesCheck.h"
1819
#include "InterfacesGlobalInitCheck.h"
1920
#include "MacroUsageCheck.h"
2021
#include "NarrowingConversionsCheck.h"
@@ -49,6 +50,8 @@ class CppCoreGuidelinesModule : public ClangTidyModule {
4950
"cppcoreguidelines-avoid-magic-numbers");
5051
CheckFactories.registerCheck<modernize::UseOverrideCheck>(
5152
"cppcoreguidelines-explicit-virtual-functions");
53+
CheckFactories.registerCheck<InitVariablesCheck>(
54+
"cppcoreguidelines-init-variables");
5255
CheckFactories.registerCheck<InterfacesGlobalInitCheck>(
5356
"cppcoreguidelines-interfaces-global-init");
5457
CheckFactories.registerCheck<MacroUsageCheck>(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//===--- InitVariablesCheck.cpp - clang-tidy ------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "InitVariablesCheck.h"
10+
11+
#include "clang/AST/ASTContext.h"
12+
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
14+
using namespace clang::ast_matchers;
15+
16+
namespace clang {
17+
namespace tidy {
18+
namespace cppcoreguidelines {
19+
20+
namespace {
21+
AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
22+
} // namespace
23+
24+
InitVariablesCheck::InitVariablesCheck(StringRef Name,
25+
ClangTidyContext *Context)
26+
: ClangTidyCheck(Name, Context),
27+
IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
28+
Options.getLocalOrGlobal("IncludeStyle", "llvm"))),
29+
MathHeader(Options.get("MathHeader", "math.h")) {}
30+
31+
void InitVariablesCheck::registerMatchers(MatchFinder *Finder) {
32+
Finder->addMatcher(varDecl(unless(hasInitializer(anything())),
33+
unless(isInstantiated()), isLocalVarDecl(),
34+
unless(isStaticLocal()), isDefinition())
35+
.bind("vardecl"),
36+
this);
37+
}
38+
39+
void InitVariablesCheck::registerPPCallbacks(const SourceManager &SM,
40+
Preprocessor *PP,
41+
Preprocessor *ModuleExpanderPP) {
42+
IncludeInserter =
43+
std::make_unique<utils::IncludeInserter>(SM, getLangOpts(), IncludeStyle);
44+
PP->addPPCallbacks(IncludeInserter->CreatePPCallbacks());
45+
}
46+
47+
void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
48+
const auto *MatchedDecl = Result.Nodes.getNodeAs<VarDecl>("vardecl");
49+
const ASTContext &Context = *Result.Context;
50+
const SourceManager &Source = Context.getSourceManager();
51+
52+
// We want to warn about cases where the type name
53+
// comes from a macro like this:
54+
//
55+
// TYPENAME_FROM_MACRO var;
56+
//
57+
// but not if the entire declaration comes from
58+
// one:
59+
//
60+
// DEFINE_SOME_VARIABLE();
61+
//
62+
// or if the definition comes from a macro like SWAP
63+
// that uses an internal temporary variable.
64+
//
65+
// Thus check that the variable name does
66+
// not come from a macro expansion.
67+
if (MatchedDecl->getEndLoc().isMacroID())
68+
return;
69+
70+
QualType TypePtr = MatchedDecl->getType();
71+
const char *InitializationString = nullptr;
72+
bool AddMathInclude = false;
73+
74+
if (TypePtr->isIntegerType())
75+
InitializationString = " = 0";
76+
else if (TypePtr->isFloatingType()) {
77+
InitializationString = " = NAN";
78+
AddMathInclude = true;
79+
} else if (TypePtr->isAnyPointerType()) {
80+
if (getLangOpts().CPlusPlus11)
81+
InitializationString = " = nullptr";
82+
else
83+
InitializationString = " = NULL";
84+
}
85+
86+
if (InitializationString) {
87+
auto Diagnostic =
88+
diag(MatchedDecl->getLocation(), "variable %0 is not initialized")
89+
<< MatchedDecl
90+
<< FixItHint::CreateInsertion(
91+
MatchedDecl->getLocation().getLocWithOffset(
92+
MatchedDecl->getName().size()),
93+
InitializationString);
94+
if (AddMathInclude) {
95+
auto IncludeHint = IncludeInserter->CreateIncludeInsertion(
96+
Source.getFileID(MatchedDecl->getBeginLoc()), MathHeader, false);
97+
if (IncludeHint)
98+
Diagnostic << *IncludeHint;
99+
}
100+
}
101+
}
102+
103+
} // namespace cppcoreguidelines
104+
} // namespace tidy
105+
} // namespace clang
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===--- InitVariablesCheck.h - clang-tidy ----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_INITVARIABLESCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_INITVARIABLESCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
#include "../utils/IncludeInserter.h"
14+
#include "../utils/OptionsUtils.h"
15+
16+
namespace clang {
17+
namespace tidy {
18+
namespace cppcoreguidelines {
19+
20+
/// Find uninitialized local variables.
21+
///
22+
/// For the user-facing documentation see:
23+
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-init-variables.html
24+
class InitVariablesCheck : public ClangTidyCheck {
25+
public:
26+
InitVariablesCheck(StringRef Name, ClangTidyContext *Context);
27+
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
28+
Preprocessor *ModuleExpanderPP) override;
29+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
30+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
31+
32+
private:
33+
std::unique_ptr<clang::tidy::utils::IncludeInserter> IncludeInserter;
34+
const utils::IncludeSorter::IncludeStyle IncludeStyle;
35+
const std::string MathHeader;
36+
};
37+
38+
} // namespace cppcoreguidelines
39+
} // namespace tidy
40+
} // namespace clang
41+
42+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_INITVARIABLESCHECK_H

clang-tools-extra/clang-tidy/objc/AvoidSpinlockCheck.cpp clang-tools-extra/clang-tidy/darwin/AvoidSpinlockCheck.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using namespace clang::ast_matchers;
1414

1515
namespace clang {
1616
namespace tidy {
17-
namespace objc {
17+
namespace darwin {
1818

1919
void AvoidSpinlockCheck::registerMatchers(MatchFinder *Finder) {
2020
Finder->addMatcher(
@@ -31,6 +31,6 @@ void AvoidSpinlockCheck::check(const MatchFinder::MatchResult &Result) {
3131
"deprecated OSSpinLock");
3232
}
3333

34-
} // namespace objc
34+
} // namespace darwin
3535
} // namespace tidy
3636
} // namespace clang

clang-tools-extra/clang-tidy/objc/AvoidSpinlockCheck.h clang-tools-extra/clang-tidy/darwin/AvoidSpinlockCheck.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H
1111

1212
#include "../ClangTidyCheck.h"
1313

1414
namespace clang {
1515
namespace tidy {
16-
namespace objc {
16+
namespace darwin {
1717

1818
/// Finds usages of OSSpinlock, which is deprecated due to potential livelock
1919
/// problems.
2020
///
2121
/// For the user-facing documentation see:
22-
/// http://clang.llvm.org/extra/clang-tidy/checks/objc-avoid-spinlock.html
22+
/// http://clang.llvm.org/extra/clang-tidy/checks/darwin-avoid-spinlock.html
2323
class AvoidSpinlockCheck : public ClangTidyCheck {
2424
public:
2525
AvoidSpinlockCheck(StringRef Name, ClangTidyContext *Context)
@@ -28,8 +28,8 @@ class AvoidSpinlockCheck : public ClangTidyCheck {
2828
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2929
};
3030

31-
} // namespace objc
31+
} // namespace darwin
3232
} // namespace tidy
3333
} // namespace clang
3434

35-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_AVOID_SPINLOCK_H
35+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_DARWIN_AVOIDSPINLOCKCHECK_H

clang-tools-extra/clang-tidy/darwin/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(LLVM_LINK_COMPONENTS support)
22

33
add_clang_library(clangTidyDarwinModule
4+
AvoidSpinlockCheck.cpp
45
DarwinTidyModule.cpp
56
DispatchOnceNonstaticCheck.cpp
67

clang-tools-extra/clang-tidy/darwin/DarwinTidyModule.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../ClangTidy.h"
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
12+
#include "AvoidSpinlockCheck.h"
1213
#include "DispatchOnceNonstaticCheck.h"
1314

1415
namespace clang {
@@ -18,6 +19,8 @@ namespace darwin {
1819
class DarwinModule : public ClangTidyModule {
1920
public:
2021
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
22+
CheckFactories.registerCheck<AvoidSpinlockCheck>(
23+
"darwin-avoid-spinlock");
2124
CheckFactories.registerCheck<DispatchOnceNonstaticCheck>(
2225
"darwin-dispatch-once-nonstatic");
2326
}
@@ -27,7 +30,7 @@ class DarwinModule : public ClangTidyModule {
2730

2831
// Register the DarwinTidyModule using this statically initialized variable.
2932
static ClangTidyModuleRegistry::Add<darwin::DarwinModule>
30-
X("misc-module", "Adds miscellaneous lint checks.");
33+
X("darwin-module", "Adds Darwin-specific lint checks.");
3134

3235
// This anchor is used to force the linker to link in the generated object file
3336
// and thus register the DarwinModule.

clang-tools-extra/clang-tidy/objc/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ set(LLVM_LINK_COMPONENTS support)
22

33
add_clang_library(clangTidyObjCModule
44
AvoidNSErrorInitCheck.cpp
5-
AvoidSpinlockCheck.cpp
65
ForbiddenSubclassingCheck.cpp
76
MissingHashCheck.cpp
87
ObjCTidyModule.cpp

clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
1212
#include "AvoidNSErrorInitCheck.h"
13-
#include "AvoidSpinlockCheck.h"
1413
#include "ForbiddenSubclassingCheck.h"
1514
#include "MissingHashCheck.h"
1615
#include "PropertyDeclarationCheck.h"
@@ -27,8 +26,6 @@ class ObjCModule : public ClangTidyModule {
2726
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
2827
CheckFactories.registerCheck<AvoidNSErrorInitCheck>(
2928
"objc-avoid-nserror-init");
30-
CheckFactories.registerCheck<AvoidSpinlockCheck>(
31-
"objc-avoid-spinlock");
3229
CheckFactories.registerCheck<ForbiddenSubclassingCheck>(
3330
"objc-forbidden-subclassing");
3431
CheckFactories.registerCheck<MissingHashCheck>(

clang-tools-extra/clangd/ClangdLSPServer.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
700700
WorkspaceEdit WE;
701701
WE.changes.emplace();
702702
for (const auto &It : R->ApplyEdits) {
703-
(*WE.changes)[URI::create(It.first()).toString()] =
703+
(*WE.changes)[URI::createFile(It.first()).toString()] =
704704
It.second.asTextEdits();
705705
}
706706
// ApplyEdit will take care of calling Reply().
@@ -1038,10 +1038,16 @@ void ClangdLSPServer::onGoToDeclaration(
10381038
void ClangdLSPServer::onSwitchSourceHeader(
10391039
const TextDocumentIdentifier &Params,
10401040
Callback<llvm::Optional<URIForFile>> Reply) {
1041-
if (auto Result = Server->switchSourceHeader(Params.uri.file()))
1042-
Reply(URIForFile::canonicalize(*Result, Params.uri.file()));
1043-
else
1044-
Reply(llvm::None);
1041+
Server->switchSourceHeader(
1042+
Params.uri.file(),
1043+
[Reply = std::move(Reply),
1044+
Params](llvm::Expected<llvm::Optional<clangd::Path>> Path) mutable {
1045+
if (!Path)
1046+
return Reply(Path.takeError());
1047+
if (*Path)
1048+
Reply(URIForFile::canonicalize(**Path, Params.uri.file()));
1049+
return Reply(llvm::None);
1050+
});
10451051
}
10461052

10471053
void ClangdLSPServer::onDocumentHighlight(

0 commit comments

Comments
 (0)