Author: ibiryukov Date: Mon Feb 12 04:48:51 2018 New Revision: 324888 URL: http://llvm.org/viewvc/llvm-project?rev=324888&view=rev Log: [clangd] Log all ignored diagnostics.
Summary: To aid debugging failures and crashes. Only part of ignored diagnostics was logged before, now we log all of them. Reviewers: ioeric, hokein, sammccall Reviewed By: hokein Subscribers: klimek, jkorous-apple, cfe-commits Differential Revision: https://reviews.llvm.org/D43123 Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp clang-tools-extra/trunk/clangd/Compiler.cpp clang-tools-extra/trunk/clangd/Compiler.h Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=324888&r1=324887&r2=324888&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Mon Feb 12 04:48:51 2018 @@ -26,7 +26,6 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/CrashRecoveryContext.h" -#include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> @@ -178,27 +177,15 @@ TextEdit toTextEdit(const FixItHint &Fix llvm::Optional<DiagWithFixIts> toClangdDiag(const clang::Diagnostic &D, DiagnosticsEngine::Level Level, const LangOptions &LangOpts) { - SmallString<64> Message; - D.FormatDiagnostic(Message); - if (!D.hasSourceManager() || !D.getLocation().isValid() || !D.getSourceManager().isInMainFile(D.getLocation())) { - - SmallString<64> Location; - if (D.hasSourceManager() && D.getLocation().isValid()) { - auto &SourceMgr = D.getSourceManager(); - auto Loc = SourceMgr.getFileLoc(D.getLocation()); - llvm::raw_svector_ostream OS(Location); - Loc.print(OS, SourceMgr); - } else { - Location = "<no-loc>"; - } - - log(llvm::formatv("Ignored diagnostic outside main file. {0}: {1}", - Location, Message)); + IgnoreDiagnostics::log(Level, D); return llvm::None; } + SmallString<64> Message; + D.FormatDiagnostic(Message); + DiagWithFixIts Result; Result.Diag.range = diagnosticRange(D, LangOpts); Result.Diag.severity = getSeverity(Level); Modified: clang-tools-extra/trunk/clangd/Compiler.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Compiler.cpp?rev=324888&r1=324887&r2=324888&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Compiler.cpp (original) +++ clang-tools-extra/trunk/clangd/Compiler.cpp Mon Feb 12 04:48:51 2018 @@ -8,12 +8,37 @@ //===---------------------------------------------------------------------===// #include "Compiler.h" +#include "Logger.h" #include "clang/Basic/TargetInfo.h" #include "clang/Lex/PreprocessorOptions.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/FormatVariadic.h" namespace clang { namespace clangd { +void IgnoreDiagnostics::log(DiagnosticsEngine::Level DiagLevel, + const clang::Diagnostic &Info) { + SmallString<64> Message; + Info.FormatDiagnostic(Message); + + SmallString<64> Location; + if (Info.hasSourceManager() && Info.getLocation().isValid()) { + auto &SourceMgr = Info.getSourceManager(); + auto Loc = SourceMgr.getFileLoc(Info.getLocation()); + llvm::raw_svector_ostream OS(Location); + Loc.print(OS, SourceMgr); + OS << ":"; + } + + clangd::log(llvm::formatv("Ignored diagnostic. {0}{1}", Location, Message)); +} + +void IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, + const clang::Diagnostic &Info) { + IgnoreDiagnostics::log(DiagLevel, Info); +} + std::unique_ptr<CompilerInstance> prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI, const PrecompiledPreamble *Preamble, Modified: clang-tools-extra/trunk/clangd/Compiler.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Compiler.h?rev=324888&r1=324887&r2=324888&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/Compiler.h (original) +++ clang-tools-extra/trunk/clangd/Compiler.h Mon Feb 12 04:48:51 2018 @@ -24,8 +24,11 @@ namespace clangd { class IgnoreDiagnostics : public DiagnosticConsumer { public: + static void log(DiagnosticsEngine::Level DiagLevel, + const clang::Diagnostic &Info); + void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, - const clang::Diagnostic &Info) override {} + const clang::Diagnostic &Info) override; }; /// Creates a compiler instance, configured so that: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits