Lines Matching +full:llvm +full:- +full:builddir
1 //===--- tools/extra/clang-tidy/ClangTidy.cpp - Clang tidy tool -----------===//
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
7 //===----------------------------------------------------------------------===//
9 /// \file This file implements a clang-tidy tool.
12 /// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
13 /// for details on setting it up with LLVM source tree.
15 //===----------------------------------------------------------------------===//
23 #include "clang-tidy-config.h"
42 #include "llvm/Support/Process.h"
54 using namespace llvm;
62 static const char *AnalyzerCheckNamePrefix = "clang-analyzer-";
72 CheckName += PD->getCheckerName();
73 Context.diag(CheckName, PD->getLocation().asLocation(),
74 PD->getShortDescription())
75 << PD->path.back()->getRanges();
78 PD->path.flatten(/*ShouldFlattenMacros=*/true)) {
79 Context.diag(CheckName, DiagPiece->getLocation().asLocation(),
80 DiagPiece->getString(), DiagnosticIDs::Note)
81 << DiagPiece->getRanges();
98 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS)
101 DiagPrinter(new TextDiagnosticPrinter(llvm::outs(), &*DiagOpts)),
105 DiagOpts->ShowColors = Context.getOptions().UseColor.value_or(
106 llvm::sys::Process::StandardOutHasColors());
107 DiagPrinter->BeginSourceFile(LangOpts);
108 if (DiagOpts->ShowColors && !llvm::sys::Process::StandardOutIsDisplayed()) {
109 llvm::sys::Process::UseANSIEscapeCodes(true);
125 Name += "," + llvm::join(Error.EnabledDiagnosticAliases, ",");
127 Name += ",-warnings-as-errors";
136 const llvm::StringMap<Replacements> *ChosenFix = nullptr;
152 llvm::Error Err = Replacements.add(R);
155 llvm::errs() << "Trying to resolve conflict: "
156 << llvm::toString(std::move(Err)) << "\n";
160 R.getOffset() + R.getLength()) -
169 llvm::errs()
178 Entry.BuildDir = Error.BuildDirectory;
201 VFS.setCurrentWorkingDirectory(FileAndReplacements.second.BuildDir);
202 llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
205 llvm::errs() << "Can't get buffer for file " << File << ": "
210 StringRef Code = Buffer.get()->getBuffer();
214 llvm::errs() << llvm::toString(Style.takeError()) << "\n";
217 llvm::Expected<tooling::Replacements> Replacements =
221 llvm::errs() << llvm::toString(Replacements.takeError()) << "\n";
224 if (llvm::Expected<tooling::Replacements> FormattedReplacements =
230 llvm::errs() << llvm::toString(FormattedReplacements.takeError())
234 llvm::errs() << "Can't apply replacements for file " << File << "\n";
240 llvm::errs() << "clang-tidy failed to apply suggested fixes.\n";
242 llvm::errs() << "clang-tidy applied " << AppliedFixes << " of "
267 const llvm::StringMap<Replacements> &Fix) {
305 StringRef BuildDir;
315 llvm::StringMap<ReplacementsWithBuildDir> FileReplacements;
346 IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
351 Module->addCheckFactories(*CheckFactories);
378 llvm::any_of(RegisteredCheckers, [&](StringRef CheckName) -> bool {
421 CheckFactories->createChecksForLanguage(&Context);
429 FinderOptions.CheckProfiling.emplace(Profiling->Records);
442 ModuleExpanderPP = ModuleExpander->getPreprocessor();
443 PP->addPPCallbacks(std::move(ModuleExpander));
447 Check->registerMatchers(&*Finder);
448 Check->registerPPCallbacks(*SM, PP, ModuleExpanderPP);
453 Consumers.push_back(Finder->newASTConsumer());
464 AnalysisConsumer->AddDiagnosticConsumer(
487 llvm::sort(CheckNames);
494 CheckFactories->createChecks(&Context);
496 Check->storeOptions(Options);
519 DiagnosticsEngine DE(llvm::makeIntrusiveRefCnt<DiagnosticIDs>(),
520 llvm::makeIntrusiveRefCnt<DiagnosticOptions>(),
531 llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS,
533 llvm::StringRef StoreCheckProfile) {
537 // Add extra arguments passed by the clang-tidy command-line.
544 if (I != AdjustedArgs.end() && !StringRef(*I).starts_with("-"))
546 AdjustedArgs.insert(I, Opts.ExtraArgsBefore->begin(),
547 Opts.ExtraArgsBefore->end());
550 AdjustedArgs.insert(AdjustedArgs.end(), Opts.ExtraArgs->begin(),
551 Opts.ExtraArgs->end());
569 IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS)
580 Invocation->getPreprocessorOpts().SetUpStaticAnalyzer = true;
591 return Factory->createASTConsumer(Compiler, File);
606 void handleErrors(llvm::ArrayRef<ClangTidyError> Errors,
609 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS) {
611 llvm::vfs::FileSystem &FileSystem =
615 llvm::report_fatal_error("Cannot get current working path.");
620 // clang-tidy running directory.
633 void exportReplacements(const llvm::StringRef MainFilePath,
660 Module.instantiate()->addCheckFactories(Factories);