diff options
| author | joerg <joerg@NetBSD.org> | 2017-08-01 19:34:09 +0000 |
|---|---|---|
| committer | joerg <joerg@NetBSD.org> | 2017-08-01 19:34:09 +0000 |
| commit | 512f2fa596afb9c4a6a025d50cf6fcc61d9304e2 (patch) | |
| tree | 13b95babd96062414a1a982935a17d5a7f2e4fce /external/bsd/llvm/dist/clang/lib/Tooling/CompilationDatabase.cpp | |
| parent | b5e3783314897bc6986dcd85a575c3b2fcc6be67 (diff) | |
Import clang r309604 from branches/release_50
Diffstat (limited to 'external/bsd/llvm/dist/clang/lib/Tooling/CompilationDatabase.cpp')
| -rw-r--r-- | external/bsd/llvm/dist/clang/lib/Tooling/CompilationDatabase.cpp | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/external/bsd/llvm/dist/clang/lib/Tooling/CompilationDatabase.cpp b/external/bsd/llvm/dist/clang/lib/Tooling/CompilationDatabase.cpp index 8ca0b2df701..0e835579e04 100644 --- a/external/bsd/llvm/dist/clang/lib/Tooling/CompilationDatabase.cpp +++ b/external/bsd/llvm/dist/clang/lib/Tooling/CompilationDatabase.cpp @@ -27,6 +27,7 @@ #include "llvm/Option/Arg.h" #include "llvm/Support/Host.h" #include "llvm/Support/Path.h" +#include "llvm/Support/raw_ostream.h" #include <sstream> #include <system_error> using namespace clang; @@ -150,23 +151,21 @@ private: // options. class UnusedInputDiagConsumer : public DiagnosticConsumer { public: - UnusedInputDiagConsumer() : Other(nullptr) {} - - // Useful for debugging, chain diagnostics to another consumer after - // recording for our own purposes. - UnusedInputDiagConsumer(DiagnosticConsumer *Other) : Other(Other) {} + UnusedInputDiagConsumer(DiagnosticConsumer &Other) : Other(Other) {} void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override { if (Info.getID() == clang::diag::warn_drv_input_file_unused) { // Arg 1 for this diagnostic is the option that didn't get used. UnusedInputs.push_back(Info.getArgStdStr(0)); + } else if (DiagLevel >= DiagnosticsEngine::Error) { + // If driver failed to create compilation object, show the diagnostics + // to user. + Other.HandleDiagnostic(DiagLevel, Info); } - if (Other) - Other->HandleDiagnostic(DiagLevel, Info); } - DiagnosticConsumer *Other; + DiagnosticConsumer &Other; SmallVector<std::string, 2> UnusedInputs; }; @@ -205,9 +204,12 @@ private: /// \li false if \c Args cannot be used for compilation jobs (e.g. /// contains an option like -E or -version). static bool stripPositionalArgs(std::vector<const char *> Args, - std::vector<std::string> &Result) { + std::vector<std::string> &Result, + std::string &ErrorMsg) { IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions(); - UnusedInputDiagConsumer DiagClient; + llvm::raw_string_ostream Output(ErrorMsg); + TextDiagnosticPrinter DiagnosticPrinter(Output, &*DiagOpts); + UnusedInputDiagConsumer DiagClient(DiagnosticPrinter); DiagnosticsEngine Diagnostics( IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts, &DiagClient, false); @@ -245,21 +247,24 @@ static bool stripPositionalArgs(std::vector<const char *> Args, const std::unique_ptr<driver::Compilation> Compilation( NewDriver->BuildCompilation(Args)); + if (!Compilation) + return false; const driver::JobList &Jobs = Compilation->getJobs(); CompileJobAnalyzer CompileAnalyzer; for (const auto &Cmd : Jobs) { - // Collect only for Assemble jobs. If we do all jobs we get duplicates - // since Link jobs point to Assemble jobs as inputs. - if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass) + // Collect only for Assemble and Compile jobs. If we do all jobs we get + // duplicates since Link jobs point to Assemble jobs as inputs. + if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass || + Cmd.getSource().getKind() == driver::Action::CompileJobClass) { CompileAnalyzer.run(&Cmd.getSource()); + } } if (CompileAnalyzer.Inputs.empty()) { - // No compile jobs found. - // FIXME: Emit a warning of some kind? + ErrorMsg = "warning: no compile jobs found\n"; return false; } @@ -280,8 +285,14 @@ static bool stripPositionalArgs(std::vector<const char *> Args, return true; } -FixedCompilationDatabase *FixedCompilationDatabase::loadFromCommandLine( - int &Argc, const char *const *Argv, Twine Directory) { +std::unique_ptr<FixedCompilationDatabase> +FixedCompilationDatabase::loadFromCommandLine(int &Argc, + const char *const *Argv, + std::string &ErrorMsg, + Twine Directory) { + ErrorMsg.clear(); + if (Argc == 0) + return nullptr; const char *const *DoubleDash = std::find(Argv, Argv + Argc, StringRef("--")); if (DoubleDash == Argv + Argc) return nullptr; @@ -289,9 +300,10 @@ FixedCompilationDatabase *FixedCompilationDatabase::loadFromCommandLine( Argc = DoubleDash - Argv; std::vector<std::string> StrippedArgs; - if (!stripPositionalArgs(CommandLine, StrippedArgs)) + if (!stripPositionalArgs(CommandLine, StrippedArgs, ErrorMsg)) return nullptr; - return new FixedCompilationDatabase(Directory, StrippedArgs); + return std::unique_ptr<FixedCompilationDatabase>( + new FixedCompilationDatabase(Directory, StrippedArgs)); } FixedCompilationDatabase:: |
