Author: alexfh Date: Tue May 6 03:10:00 2014 New Revision: 208068 URL: http://llvm.org/viewvc/llvm-project?rev=208068&view=rev Log: Fix a crash when diagnostic points to a macro definition on command line.
Reviewers: klimek Reviewed By: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D3620 Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp clang-tools-extra/trunk/test/clang-tidy/diagnostic.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=208068&r1=208067&r2=208068&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Tue May 6 03:10:00 2014 @@ -239,7 +239,10 @@ bool ClangTidyDiagnosticConsumer::relate if (FID == Sources.getMainFileID()) return true; - return HeaderFilter.match(Sources.getFileEntryForID(FID)->getName()); + const FileEntry *File = Sources.getFileEntryForID(FID); + // -DMACRO definitions on the command line have locations in a virtual buffer + // that doesn't have a FileEntry. Don't skip these as well. + return !File || HeaderFilter.match(File->getName()); } struct LessClangTidyError { Modified: 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=208068&r1=208067&r2=208068&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp Tue May 6 03:10:00 2014 @@ -1,6 +1,7 @@ // RUN: clang-tidy -disable-checks='' %s.nonexistent.cpp -- | FileCheck -check-prefix=CHECK1 %s // RUN: clang-tidy -disable-checks='' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK2 %s // RUN: clang-tidy -checks='(google-explicit-constructor|clang-diagnostic-literal-conversion)' -disable-checks='' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK3 %s +// RUN: clang-tidy -checks='clang-diagnostic-macro-redefined' -disable-checks='' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s // CHECK1-NOT: warning // CHECK2-NOT: warning @@ -19,3 +20,6 @@ class A { A(int) {} }; // CHECK2-NOT: warning: // CHECK3-NOT: warning: + +#define MACRO_FROM_COMMAND_LINE +// CHECK4: :[[@LINE-1]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
