]> granicus.if.org Git - clang/commitdiff
Don't include FixIts with a null replacement range. Fixes <rdar://problem/11040133>.
authorTed Kremenek <kremenek@apple.com>
Tue, 20 Mar 2012 20:49:45 +0000 (20:49 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 20 Mar 2012 20:49:45 +0000 (20:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153122 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
test/ARCMT/check-with-serialized-diag.m
test/Misc/serialized-diags.c
tools/c-index-test/c-index-test.c

index 1634306fc387e86ec25066f30f16e57257c529e9..e1571786dd5ceaff7159c1855a2ed19f3b91ca5d 100644 (file)
@@ -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;
 }
 
index 57742d92c5d522962362e6e2796e491500ee6268..d8073d04693176569d6c40cae9e39119cff62d7b 100644 (file)
@@ -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
+
index f4de8401e929949bac3cd993815e313cede0d8d3..73ac0507fcb9328407252f83ab974f81f796139f 100644 (file)
@@ -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
 
index b57b52efe8be4f61c166bb46cf3282fa37d0d2e1..67de8508cd5ee30185c0b1d4453ef4b930311fdf 100644 (file)
@@ -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;