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

llvm-svn: 200702
This commit is contained in:
Alexander Kornienko 2014-02-03 15:55:35 +00:00
parent 8d58767b34
commit 6d129d5454
2 changed files with 8 additions and 1 deletions

View File

@ -82,7 +82,9 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
// 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(

View File

@ -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'