ilya-biryukov created this revision.
ilya-biryukov added reviewers: ioeric, hokein, sammccall.
Herald added subscribers: jkorous-apple, klimek.

To aid debugging failures and crashes.
Only part of ignored diagnostics was logged before, now we log all of
them.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43123

Files:
  clangd/ClangdUnit.cpp
  clangd/Compiler.cpp
  clangd/Compiler.h

Index: clangd/Compiler.h
===================================================================
--- clangd/Compiler.h
+++ clangd/Compiler.h
@@ -24,8 +24,11 @@
 
 class IgnoreDiagnostics : public DiagnosticConsumer {
 public:
+  static void logIgnoredDiag(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:
Index: clangd/Compiler.cpp
===================================================================
--- clangd/Compiler.cpp
+++ clangd/Compiler.cpp
@@ -8,12 +8,38 @@
 //===---------------------------------------------------------------------===//
 
 #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::logIgnoredDiag(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 << ":";
+  }
+
+  log(llvm::formatv("Ignored diagnostic. {0}{1}", Location,
+                    Message));
+}
+
+void IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+                                         const clang::Diagnostic &Info) {
+  logIgnoredDiag(DiagLevel, Info);
+}
+
 std::unique_ptr<CompilerInstance>
 prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
                         const PrecompiledPreamble *Preamble,
Index: clangd/ClangdUnit.cpp
===================================================================
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -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 @@
 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::logIgnoredDiag(Level, D);
     return llvm::None;
   }
 
+  SmallString<64> Message;
+  D.FormatDiagnostic(Message);
+
   DiagWithFixIts Result;
   Result.Diag.range = diagnosticRange(D, LangOpts);
   Result.Diag.severity = getSeverity(Level);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to