Skip to content

Commit bb8d70b

Browse files
Merge from 'master' to 'sycl-web' (intel#22)
CONFLICT (content): Merge conflict in clang/lib/CodeGen/CodeGenFunction.h
2 parents bed8916 + 3bd0672 commit bb8d70b

File tree

137 files changed

+2385
-1428
lines changed

Some content is hidden

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

137 files changed

+2385
-1428
lines changed

clang-tools-extra/clangd/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ add_clang_library(clangDaemon
8181
SemanticSelection.cpp
8282
SourceCode.cpp
8383
QueryDriverDatabase.cpp
84+
TidyProvider.cpp
8485
TUScheduler.cpp
8586
URI.cpp
8687
XRefs.cpp

clang-tools-extra/clangd/ClangdServer.cpp

+2-49
Original file line numberDiff line numberDiff line change
@@ -114,40 +114,6 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
114114
bool TheiaSemanticHighlighting;
115115
};
116116

117-
// Set of clang-tidy checks that don't work well in clangd, either due to
118-
// crashes or false positives.
119-
// Returns a clang-tidy filter string: -check1,-check2.
120-
llvm::StringRef getUnusableTidyChecks() {
121-
static const std::string FalsePositives =
122-
llvm::join_items(", ",
123-
// Check relies on seeing ifndef/define/endif directives,
124-
// clangd doesn't replay those when using a preamble.
125-
"-llvm-header-guard");
126-
static const std::string CrashingChecks =
127-
llvm::join_items(", ",
128-
// Check can choke on invalid (intermediate) c++ code,
129-
// which is often the case when clangd tries to build an
130-
// AST.
131-
"-bugprone-use-after-move");
132-
static const std::string UnusableTidyChecks =
133-
llvm::join_items(", ", FalsePositives, CrashingChecks);
134-
return UnusableTidyChecks;
135-
}
136-
137-
// Returns a clang-tidy options string: check1,check2.
138-
llvm::StringRef getDefaultTidyChecks() {
139-
// These default checks are chosen for:
140-
// - low false-positive rate
141-
// - providing a lot of value
142-
// - being reasonably efficient
143-
static const std::string DefaultChecks = llvm::join_items(
144-
",", "readability-misleading-indentation", "readability-deleted-default",
145-
"bugprone-integer-division", "bugprone-sizeof-expression",
146-
"bugprone-suspicious-missing-comma", "bugprone-unused-raii",
147-
"bugprone-unused-return-value", "misc-unused-using-decls",
148-
"misc-unused-alias-decls", "misc-definitions-in-headers");
149-
return DefaultChecks;
150-
}
151117
} // namespace
152118

153119
ClangdServer::Options ClangdServer::optsForTest() {
@@ -178,7 +144,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
178144
? new FileIndex(Opts.HeavyweightDynamicSymbolIndex,
179145
Opts.CollectMainFileRefs)
180146
: nullptr),
181-
GetClangTidyOptions(Opts.GetClangTidyOptions),
147+
ClangTidyProvider(Opts.ClangTidyProvider),
182148
SuggestMissingIncludes(Opts.SuggestMissingIncludes),
183149
BuildRecoveryAST(Opts.BuildRecoveryAST),
184150
PreserveRecoveryASTType(Opts.PreserveRecoveryASTType),
@@ -236,20 +202,6 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
236202
llvm::StringRef Version,
237203
WantDiagnostics WantDiags, bool ForceRebuild) {
238204
ParseOptions Opts;
239-
Opts.ClangTidyOpts = tidy::ClangTidyOptions::getDefaults();
240-
// FIXME: call tidy options builder on the worker thread, it can do IO.
241-
if (GetClangTidyOptions)
242-
Opts.ClangTidyOpts =
243-
GetClangTidyOptions(*TFS.view(/*CWD=*/llvm::None), File);
244-
if (Opts.ClangTidyOpts.Checks.hasValue()) {
245-
// If the set of checks was configured, make sure clangd incompatible ones
246-
// are disabled.
247-
Opts.ClangTidyOpts.Checks = llvm::join_items(
248-
", ", *Opts.ClangTidyOpts.Checks, getUnusableTidyChecks());
249-
} else {
250-
// Otherwise provide a nice set of defaults.
251-
Opts.ClangTidyOpts.Checks = getDefaultTidyChecks().str();
252-
}
253205
Opts.SuggestMissingIncludes = SuggestMissingIncludes;
254206

255207
// Compile command is set asynchronously during update, as it can be slow.
@@ -260,6 +212,7 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
260212
Inputs.ForceRebuild = ForceRebuild;
261213
Inputs.Opts = std::move(Opts);
262214
Inputs.Index = Index;
215+
Inputs.ClangTidyProvider = ClangTidyProvider;
263216
Inputs.Opts.BuildRecoveryAST = BuildRecoveryAST;
264217
Inputs.Opts.PreserveRecoveryASTType = PreserveRecoveryASTType;
265218
bool NewFile = WorkScheduler.update(File, Inputs, WantDiags);

clang-tools-extra/clangd/ClangdServer.h

+4-14
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@
4141

4242
namespace clang {
4343
namespace clangd {
44-
45-
/// When set, used by ClangdServer to get clang-tidy options for each particular
46-
/// file. Must be thread-safe. We use this instead of ClangTidyOptionsProvider
47-
/// to allow reading tidy configs from the VFS used for parsing.
48-
using ClangTidyOptionsBuilder = std::function<tidy::ClangTidyOptions(
49-
llvm::vfs::FileSystem &, llvm::StringRef /*File*/)>;
50-
5144
/// Manages a collection of source files and derived data (ASTs, indexes),
5245
/// and provides language-aware features such as code completion.
5346
///
@@ -121,12 +114,9 @@ class ClangdServer {
121114
/// If set, queried to obtain the configuration to handle each request.
122115
config::Provider *ConfigProvider = nullptr;
123116

124-
/// If set, enable clang-tidy in clangd and use to it get clang-tidy
125-
/// configurations for a particular file.
126-
/// Clangd supports only a small subset of ClangTidyOptions, these options
127-
/// (Checks, CheckOptions) are about which clang-tidy checks will be
128-
/// enabled.
129-
ClangTidyOptionsBuilder GetClangTidyOptions;
117+
/// The Options provider to use when running clang-tidy. If null, clang-tidy
118+
/// checks will be disabled.
119+
TidyProviderRef ClangTidyProvider;
130120

131121
/// If true, force -frecovery-ast flag.
132122
/// If false, respect the value in clang.
@@ -389,7 +379,7 @@ class ClangdServer {
389379
std::vector<std::unique_ptr<SymbolIndex>> MergedIdx;
390380

391381
// When set, provides clang-tidy options for a specific file.
392-
ClangTidyOptionsBuilder GetClangTidyOptions;
382+
TidyProviderRef ClangTidyProvider;
393383

394384
// If this is true, suggest include insertion fixes for diagnostic errors that
395385
// can be caused by missing includes (e.g. member access in incomplete type).

clang-tools-extra/clangd/Compiler.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
1616
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
1717

18-
#include "../clang-tidy/ClangTidyOptions.h"
1918
#include "GlobalCompilationDatabase.h"
19+
#include "TidyProvider.h"
2020
#include "index/Index.h"
2121
#include "support/ThreadsafeFS.h"
2222
#include "clang/Frontend/CompilerInstance.h"
@@ -37,7 +37,6 @@ class IgnoreDiagnostics : public DiagnosticConsumer {
3737

3838
// Options to run clang e.g. when parsing AST.
3939
struct ParseOptions {
40-
tidy::ClangTidyOptions ClangTidyOpts;
4140
bool SuggestMissingIncludes = false;
4241
bool BuildRecoveryAST = false;
4342
bool PreserveRecoveryASTType = false;
@@ -56,6 +55,7 @@ struct ParseInputs {
5655
// Used to recover from diagnostics (e.g. find missing includes for symbol).
5756
const SymbolIndex *Index = nullptr;
5857
ParseOptions Opts = ParseOptions();
58+
TidyProviderRef ClangTidyProvider = {};
5959
};
6060

6161
/// Builds compiler invocation that could be used to build AST or preamble.

clang-tools-extra/clangd/ParsedAST.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "IncludeFixer.h"
1818
#include "Preamble.h"
1919
#include "SourceCode.h"
20+
#include "TidyProvider.h"
2021
#include "index/CanonicalIncludes.h"
2122
#include "index/Index.h"
2223
#include "support/Logger.h"
@@ -292,13 +293,15 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
292293
llvm::Optional<tidy::ClangTidyContext> CTContext;
293294
{
294295
trace::Span Tracer("ClangTidyInit");
296+
tidy::ClangTidyOptions ClangTidyOpts =
297+
getTidyOptionsForFile(Inputs.ClangTidyProvider, Filename);
295298
dlog("ClangTidy configuration for file {0}: {1}", Filename,
296-
tidy::configurationAsText(Inputs.Opts.ClangTidyOpts));
299+
tidy::configurationAsText(ClangTidyOpts));
297300
tidy::ClangTidyCheckFactories CTFactories;
298301
for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
299302
E.instantiate()->addCheckFactories(CTFactories);
300303
CTContext.emplace(std::make_unique<tidy::DefaultOptionsProvider>(
301-
tidy::ClangTidyGlobalOptions(), Inputs.Opts.ClangTidyOpts));
304+
tidy::ClangTidyGlobalOptions(), ClangTidyOpts));
302305
CTContext->setDiagnosticsEngine(&Clang->getDiagnostics());
303306
CTContext->setASTContext(&Clang->getASTContext());
304307
CTContext->setCurrentFile(Filename);

0 commit comments

Comments
 (0)