[clang-tools-extra] r200702 - Fix crash when handling an argument parsing-related warning.

Alexander Kornienko alexfh at google.com
Mon Feb 3 07:55:35 PST 2014


Author: alexfh
Date: Mon Feb  3 09:55:35 2014
New Revision: 200702

URL: http://llvm.org/viewvc/llvm-project?rev=200702&view=rev
Log:
Fix crash when handling an argument parsing-related warning.

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

Reviewers: klimek, djasper

Reviewed By: djasper

CC: cfe-commits

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

Added:
    clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=200702&r1=200701&r2=200702&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Mon Feb  3 09:55:35 2014
@@ -82,7 +82,9 @@ void ClangTidyDiagnosticConsumer::Handle
   // 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()))
+  // Let argument parsing-related warnings through.
+  if (Diags->hasSourceManager() &&
+      Diags->getSourceManager().isInSystemHeader(Info.getLocation()))
     return;
   if (DiagLevel != DiagnosticsEngine::Note) {
     Errors.push_back(

Added: clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp?rev=200702&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp Mon Feb  3 09:55:35 2014
@@ -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'





More information about the cfe-commits mailing list