[PATCH] Fix a crash when diagnostic points to a macro definition on command line.
Alexander Kornienko
alexfh at google.com
Tue May 6 01:03:32 PDT 2014
Hi klimek,
http://reviews.llvm.org/D3620
Files:
clang-tidy/ClangTidyDiagnosticConsumer.cpp
test/clang-tidy/diagnostic.cpp
Index: clang-tidy/ClangTidyDiagnosticConsumer.cpp
===================================================================
--- clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -239,7 +239,10 @@
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 {
Index: test/clang-tidy/diagnostic.cpp
===================================================================
--- test/clang-tidy/diagnostic.cpp
+++ test/clang-tidy/diagnostic.cpp
@@ -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 @@
// CHECK2-NOT: warning:
// CHECK3-NOT: warning:
+
+#define MACRO_FROM_COMMAND_LINE
+// CHECK4: :[[@LINE-1]]:9: warning: 'MACRO_FROM_COMMAND_LINE' macro redefined
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3620.9100.patch
Type: text/x-patch
Size: 1609 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140506/9f29e741/attachment.bin>
More information about the cfe-commits
mailing list