diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h index 1634306fc387..e1571786dd5c 100644 --- a/clang/include/clang/Basic/Diagnostic.h +++ b/clang/include/clang/Basic/Diagnostic.h @@ -946,7 +946,8 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, const FixItHint &Hint) { - DB.AddFixItHint(Hint); + if (!Hint.isNull()) + DB.AddFixItHint(Hint); return DB; } diff --git a/clang/test/ARCMT/check-with-serialized-diag.m b/clang/test/ARCMT/check-with-serialized-diag.m index 57742d92c5d5..d8073d046931 100644 --- a/clang/test/ARCMT/check-with-serialized-diag.m +++ b/clang/test/ARCMT/check-with-serialized-diag.m @@ -36,13 +36,20 @@ void test1(A *a, struct UnsafeS *unsafeS) { } // RUN: not %clang_cc1 -arcmt-check -triple x86_64-apple-darwin10 %s -serialize-diagnostic-file %t.diag -// RUN: c-index-test -read-diagnostics %t.diag 2>&1 | FileCheck %s +// RUN: c-index-test -read-diagnostics %t.diag > %t 2>&1 +// RUN: FileCheck --input-file=%t %s // CHECK: {{.*}}check-with-serialized-diag.m:32:4: error: [rewriter] it is not safe to remove 'retain' message on an __unsafe_unretained type +// CHECK-NEXT: Number FIXITs = 0 // CHECK-NEXT: {{.*}}check-with-serialized-diag.m:34:4: error: [rewriter] it is not safe to remove 'retain' message on a global variable +// CHECK-NEXT: Number FIXITs = 0 // CHECK-NEXT: {{.*}}check-with-serialized-diag.m:32:4: error: ARC forbids explicit message send of 'retain' // CHECK-NEXT: Range: {{.*}}check-with-serialized-diag.m:32:23 {{.*}}check-with-serialized-diag.m:32:29 +// CHECK-NEXT: Number FIXITs = 0 // CHECK-NEXT: {{.*}}check-with-serialized-diag.m:34:4: error: ARC forbids explicit message send of 'retain' // CHECK-NEXT: Range: {{.*}}check-with-serialized-diag.m:34:15 {{.*}}check-with-serialized-diag.m:34:21 +// CHECK-NEXT: Number FIXITs = 0 // CHECK-NEXT: {{.*}}check-with-serialized-diag.m:35:4: error: ARC forbids explicit message send of 'retainCount' // CHECK-NEXT: Range: {{.*}}check-with-serialized-diag.m:35:6 {{.*}}check-with-serialized-diag.m:35:17 +// CHECK-NEXT: Number FIXITs = 0 + diff --git a/clang/test/Misc/serialized-diags.c b/clang/test/Misc/serialized-diags.c index f4de8401e929..73ac0507fcb9 100644 --- a/clang/test/Misc/serialized-diags.c +++ b/clang/test/Misc/serialized-diags.c @@ -25,9 +25,15 @@ void testMacro() { // Test handling of issues from #includes. #include "serialized-diags.h" +// Test handling of warnings that have empty fixits. +void rdar11040133() { + unsigned x; +} + // RUN: rm -f %t -// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t > /dev/null 2>&1 || true -// RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck %s +// RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t.diag > /dev/null 2>&1 || true +// RUN: c-index-test -read-diagnostics %t.diag > %t 2>&1 +// RUN: FileCheck --input-file=%t %s // This test case tests that we can handle multiple diagnostics which contain // FIXITs at different levels (one at the note, another at the main diagnostic). @@ -55,5 +61,8 @@ void testMacro() { // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int'; [-Wint-conversion] // CHECK: Range: {{.*[/\\]}}serialized-diags.h:5:16 {{.*[/\\]}}serialized-diags.h:5:17 // CHECK: +-{{.*[/\\]}}serialized-diags.c:26:10: note: in file included from {{.*[/\\]}}serialized-diags.c:26: [] -// CHECK: Number of diagnostics: 5 +// CHECK: Number FIXITs = 0 +// CHECK: {{.*[/\\]}}serialized-diags.c:30:12: warning: unused variable 'x' +// CHECK: Number FIXITs = 0 +// CHECK: Number of diagnostics: 6 diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index b57b52efe8be..67de8508cd5e 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -381,6 +381,7 @@ void PrintDiagnostic(CXDiagnostic Diagnostic) { return; num_fixits = clang_getDiagnosticNumFixIts(Diagnostic); + fprintf(stderr, "Number FIX-ITs = %d\n", num_fixits); for (i = 0; i != num_fixits; ++i) { CXSourceRange range; CXString insertion_text = clang_getDiagnosticFixIt(Diagnostic, i, &range); @@ -2501,6 +2502,7 @@ static void printRanges(CXDiagnostic D, unsigned indent) { static void printFixIts(CXDiagnostic D, unsigned indent) { unsigned i, n = clang_getDiagnosticNumFixIts(D); + fprintf(stderr, "Number FIXITs = %d\n", n); for (i = 0 ; i < n; ++i) { CXSourceRange ReplacementRange; CXString text;