Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (intel#22)
Browse files Browse the repository at this point in the history
  CONFLICT (content): Merge conflict in clang/lib/CodeGen/CodeGenFunction.h
  • Loading branch information
aelovikov-intel committed Nov 25, 2020
2 parents bed8916 + 3bd0672 commit bb8d70b
Show file tree
Hide file tree
Showing 137 changed files with 2,385 additions and 1,428 deletions.
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ add_clang_library(clangDaemon
SemanticSelection.cpp
SourceCode.cpp
QueryDriverDatabase.cpp
TidyProvider.cpp
TUScheduler.cpp
URI.cpp
XRefs.cpp
Expand Down
51 changes: 2 additions & 49 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,40 +114,6 @@ struct UpdateIndexCallbacks : public ParsingCallbacks {
bool TheiaSemanticHighlighting;
};

// Set of clang-tidy checks that don't work well in clangd, either due to
// crashes or false positives.
// Returns a clang-tidy filter string: -check1,-check2.
llvm::StringRef getUnusableTidyChecks() {
static const std::string FalsePositives =
llvm::join_items(", ",
// Check relies on seeing ifndef/define/endif directives,
// clangd doesn't replay those when using a preamble.
"-llvm-header-guard");
static const std::string CrashingChecks =
llvm::join_items(", ",
// Check can choke on invalid (intermediate) c++ code,
// which is often the case when clangd tries to build an
// AST.
"-bugprone-use-after-move");
static const std::string UnusableTidyChecks =
llvm::join_items(", ", FalsePositives, CrashingChecks);
return UnusableTidyChecks;
}

// Returns a clang-tidy options string: check1,check2.
llvm::StringRef getDefaultTidyChecks() {
// These default checks are chosen for:
// - low false-positive rate
// - providing a lot of value
// - being reasonably efficient
static const std::string DefaultChecks = llvm::join_items(
",", "readability-misleading-indentation", "readability-deleted-default",
"bugprone-integer-division", "bugprone-sizeof-expression",
"bugprone-suspicious-missing-comma", "bugprone-unused-raii",
"bugprone-unused-return-value", "misc-unused-using-decls",
"misc-unused-alias-decls", "misc-definitions-in-headers");
return DefaultChecks;
}
} // namespace

ClangdServer::Options ClangdServer::optsForTest() {
Expand Down Expand Up @@ -178,7 +144,7 @@ ClangdServer::ClangdServer(const GlobalCompilationDatabase &CDB,
? new FileIndex(Opts.HeavyweightDynamicSymbolIndex,
Opts.CollectMainFileRefs)
: nullptr),
GetClangTidyOptions(Opts.GetClangTidyOptions),
ClangTidyProvider(Opts.ClangTidyProvider),
SuggestMissingIncludes(Opts.SuggestMissingIncludes),
BuildRecoveryAST(Opts.BuildRecoveryAST),
PreserveRecoveryASTType(Opts.PreserveRecoveryASTType),
Expand Down Expand Up @@ -236,20 +202,6 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
llvm::StringRef Version,
WantDiagnostics WantDiags, bool ForceRebuild) {
ParseOptions Opts;
Opts.ClangTidyOpts = tidy::ClangTidyOptions::getDefaults();
// FIXME: call tidy options builder on the worker thread, it can do IO.
if (GetClangTidyOptions)
Opts.ClangTidyOpts =
GetClangTidyOptions(*TFS.view(/*CWD=*/llvm::None), File);
if (Opts.ClangTidyOpts.Checks.hasValue()) {
// If the set of checks was configured, make sure clangd incompatible ones
// are disabled.
Opts.ClangTidyOpts.Checks = llvm::join_items(
", ", *Opts.ClangTidyOpts.Checks, getUnusableTidyChecks());
} else {
// Otherwise provide a nice set of defaults.
Opts.ClangTidyOpts.Checks = getDefaultTidyChecks().str();
}
Opts.SuggestMissingIncludes = SuggestMissingIncludes;

// Compile command is set asynchronously during update, as it can be slow.
Expand All @@ -260,6 +212,7 @@ void ClangdServer::addDocument(PathRef File, llvm::StringRef Contents,
Inputs.ForceRebuild = ForceRebuild;
Inputs.Opts = std::move(Opts);
Inputs.Index = Index;
Inputs.ClangTidyProvider = ClangTidyProvider;
Inputs.Opts.BuildRecoveryAST = BuildRecoveryAST;
Inputs.Opts.PreserveRecoveryASTType = PreserveRecoveryASTType;
bool NewFile = WorkScheduler.update(File, Inputs, WantDiags);
Expand Down
18 changes: 4 additions & 14 deletions clang-tools-extra/clangd/ClangdServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@

namespace clang {
namespace clangd {

/// When set, used by ClangdServer to get clang-tidy options for each particular
/// file. Must be thread-safe. We use this instead of ClangTidyOptionsProvider
/// to allow reading tidy configs from the VFS used for parsing.
using ClangTidyOptionsBuilder = std::function<tidy::ClangTidyOptions(
llvm::vfs::FileSystem &, llvm::StringRef /*File*/)>;

/// Manages a collection of source files and derived data (ASTs, indexes),
/// and provides language-aware features such as code completion.
///
Expand Down Expand Up @@ -121,12 +114,9 @@ class ClangdServer {
/// If set, queried to obtain the configuration to handle each request.
config::Provider *ConfigProvider = nullptr;

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

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

// When set, provides clang-tidy options for a specific file.
ClangTidyOptionsBuilder GetClangTidyOptions;
TidyProviderRef ClangTidyProvider;

// If this is true, suggest include insertion fixes for diagnostic errors that
// can be caused by missing includes (e.g. member access in incomplete type).
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_COMPILER_H

#include "../clang-tidy/ClangTidyOptions.h"
#include "GlobalCompilationDatabase.h"
#include "TidyProvider.h"
#include "index/Index.h"
#include "support/ThreadsafeFS.h"
#include "clang/Frontend/CompilerInstance.h"
Expand All @@ -37,7 +37,6 @@ class IgnoreDiagnostics : public DiagnosticConsumer {

// Options to run clang e.g. when parsing AST.
struct ParseOptions {
tidy::ClangTidyOptions ClangTidyOpts;
bool SuggestMissingIncludes = false;
bool BuildRecoveryAST = false;
bool PreserveRecoveryASTType = false;
Expand All @@ -56,6 +55,7 @@ struct ParseInputs {
// Used to recover from diagnostics (e.g. find missing includes for symbol).
const SymbolIndex *Index = nullptr;
ParseOptions Opts = ParseOptions();
TidyProviderRef ClangTidyProvider = {};
};

/// Builds compiler invocation that could be used to build AST or preamble.
Expand Down
7 changes: 5 additions & 2 deletions clang-tools-extra/clangd/ParsedAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "IncludeFixer.h"
#include "Preamble.h"
#include "SourceCode.h"
#include "TidyProvider.h"
#include "index/CanonicalIncludes.h"
#include "index/Index.h"
#include "support/Logger.h"
Expand Down Expand Up @@ -292,13 +293,15 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
llvm::Optional<tidy::ClangTidyContext> CTContext;
{
trace::Span Tracer("ClangTidyInit");
tidy::ClangTidyOptions ClangTidyOpts =
getTidyOptionsForFile(Inputs.ClangTidyProvider, Filename);
dlog("ClangTidy configuration for file {0}: {1}", Filename,
tidy::configurationAsText(Inputs.Opts.ClangTidyOpts));
tidy::configurationAsText(ClangTidyOpts));
tidy::ClangTidyCheckFactories CTFactories;
for (const auto &E : tidy::ClangTidyModuleRegistry::entries())
E.instantiate()->addCheckFactories(CTFactories);
CTContext.emplace(std::make_unique<tidy::DefaultOptionsProvider>(
tidy::ClangTidyGlobalOptions(), Inputs.Opts.ClangTidyOpts));
tidy::ClangTidyGlobalOptions(), ClangTidyOpts));
CTContext->setDiagnosticsEngine(&Clang->getDiagnostics());
CTContext->setASTContext(&Clang->getASTContext());
CTContext->setCurrentFile(Filename);
Expand Down
Loading

0 comments on commit bb8d70b

Please sign in to comment.