[PATCH] Fix crash when handling an argument parsing-related warning.

Alexander Kornienko alexfh at google.com
Mon Feb 3 07:44:37 PST 2014


Hi klimek, djasper,

Don't crash on warnings coming before the translation unit starts.

http://llvm-reviews.chandlerc.com/D2676

Files:
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  test/clang-tidy/diagnostic.cpp

Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -82,7 +82,9 @@
   // FIXME: Demultiplex diagnostics.
   // FIXME: Ensure that we don't get notes from user code related to errors
   // from non-user code.
-  if (Diags->getSourceManager().isInSystemHeader(Info.getLocation()))
+  if (Diags->hasSourceManager() && // Let argument parsing-related warnings
+                                   // through.
+      Diags->getSourceManager().isInSystemHeader(Info.getLocation()))
     return;
   if (DiagLevel != DiagnosticsEngine::Note) {
     Errors.push_back(
Index: test/clang-tidy/diagnostic.cpp
===================================================================
--- /dev/null
+++ test/clang-tidy/diagnostic.cpp
@@ -0,0 +1,5 @@
+// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
+// RUN: clang-tidy %t.cpp -- -fan-unknown-option > %t2.cpp
+// RUN: FileCheck -input-file=%t2.cpp %s
+
+// CHECK: warning: unknown argument: '-fan-unknown-option'
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2676.1.patch
Type: text/x-patch
Size: 1101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140203/66197fd1/attachment.bin>


More information about the cfe-commits mailing list