diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-11-29 00:30:52 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-11-29 00:30:52 +0000 |
commit | 952538d48d75b2c01d98002a46691638f9f9a4ac (patch) | |
tree | 96b98da96b7b9e8785d0133154c98c935525ca7e | |
parent | ee77d3d70973dcfdb7e571f1139801f6dbc144a3 (diff) |
Fix serialized diagnostics to handle FixIts that only remove text. Fixes <rdar://problem/10473903>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145339 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | test/Misc/serialized-diags.c | 16 | ||||
-rw-r--r-- | tools/libclang/CXLoadedDiagnostic.cpp | 23 |
2 files changed, 33 insertions, 6 deletions
diff --git a/test/Misc/serialized-diags.c b/test/Misc/serialized-diags.c index 9cbb72e2b0..7cdac53b84 100644 --- a/test/Misc/serialized-diags.c +++ b/test/Misc/serialized-diags.c @@ -8,6 +8,13 @@ void bar() { dragon = dragon + 1 } +// Test handling of FixIts that only remove text. +int baz(); +void qux(int x) { + if ((x == baz())) + return; +} + // RUN: rm -f %t // RUN: %clang -Wall -fsyntax-only %s --serialize-diagnostics %t 2>&1 /dev/null || true // RUN: c-index-test -read-diagnostics %t 2>&1 | FileCheck %s @@ -21,3 +28,12 @@ void bar() { // CHECK: +-FIXIT: ({{.*[/\\]}}serialized-diags.c:2:13 - {{.*[/\\]}}serialized-diags.c:2:13): " = 0" // CHECK: {{.*[/\\]}}serialized-diags.c:8:22: error: expected ';' after expression [] // CHECK: FIXIT: ({{.*[/\\]}}serialized-diags.c:8:22 - {{.*[/\\]}}serialized-diags.c:8:22): ";" +// CHECK: {{.*[/\\]}}serialized-diags.c:14:10: warning: equality comparison with extraneous parentheses [-Wparentheses-equality] +// CHECK: Range: {{.*[/\\]}}serialized-diags.c:14:8 {{.*[/\\]}}serialized-diags.c:14:18 +// CHECK: +-{{.*[/\\]}}serialized-diags.c:14:10: note: remove extraneous parentheses around the comparison to silence this warning [] +// CHECK: +-FIXIT: ({{.*[/\\]}}serialized-diags.c:14:7 - {{.*[/\\]}}serialized-diags.c:14:8): "" +// CHECK: +-FIXIT: ({{.*[/\\]}}serialized-diags.c:14:18 - {{.*[/\\]}}serialized-diags.c:14:19): "" +// CHECK: +-{{.*[/\\]}}serialized-diags.c:14:10: note: use '=' to turn this equality comparison into an assignment [] +// CHECK: +-FIXIT: ({{.*[/\\]}}serialized-diags.c:14:10 - {{.*[/\\]}}serialized-diags.c:14:12): "=" +// CHECK: Number of diagnostics: 3 + diff --git a/tools/libclang/CXLoadedDiagnostic.cpp b/tools/libclang/CXLoadedDiagnostic.cpp index 510f617c58..61b9e33c2d 100644 --- a/tools/libclang/CXLoadedDiagnostic.cpp +++ b/tools/libclang/CXLoadedDiagnostic.cpp @@ -220,14 +220,16 @@ class DiagLoader { Strings &strings, llvm::StringRef errorContext, RecordData &Record, const char *BlobStart, - unsigned BlobLen); + unsigned BlobLen, + bool allowEmptyString = false); LoadResult readString(CXLoadedDiagnosticSetImpl &TopDiags, llvm::StringRef &RetStr, llvm::StringRef errorContext, RecordData &Record, const char *BlobStart, - unsigned BlobLen); + unsigned BlobLen, + bool allowEmptyString = false); LoadResult readRange(CXLoadedDiagnosticSetImpl &TopDiags, RecordData &Record, unsigned RecStartIdx, @@ -445,7 +447,8 @@ LoadResult DiagLoader::readString(CXLoadedDiagnosticSetImpl &TopDiags, llvm::StringRef errorContext, RecordData &Record, const char *BlobStart, - unsigned BlobLen) { + unsigned BlobLen, + bool allowEmptyString) { // Basic buffer overflow check. if (BlobLen > 65536) { @@ -453,6 +456,11 @@ LoadResult DiagLoader::readString(CXLoadedDiagnosticSetImpl &TopDiags, std::string(errorContext)); return Failure; } + + if (allowEmptyString && Record.size() >= 1 && BlobLen == 0) { + RetStr = ""; + return Success; + } if (Record.size() < 1 || BlobLen == 0) { reportInvalidFile(std::string("Corrupted ") + std::string(errorContext) @@ -469,9 +477,11 @@ LoadResult DiagLoader::readString(CXLoadedDiagnosticSetImpl &TopDiags, llvm::StringRef errorContext, RecordData &Record, const char *BlobStart, - unsigned BlobLen) { + unsigned BlobLen, + bool allowEmptyString) { llvm::StringRef RetStr; - if (readString(TopDiags, RetStr, errorContext, Record, BlobStart, BlobLen)) + if (readString(TopDiags, RetStr, errorContext, Record, BlobStart, BlobLen, + allowEmptyString)) return Failure; strings[Record[0]] = RetStr; return Success; @@ -627,7 +637,8 @@ LoadResult DiagLoader::readDiagnosticBlock(llvm::BitstreamCursor &Stream, if (readRange(TopDiags, Record, 0, SR)) return Failure; llvm::StringRef RetStr; - if (readString(TopDiags, RetStr, "FIXIT", Record, BlobStart, BlobLen)) + if (readString(TopDiags, RetStr, "FIXIT", Record, BlobStart, BlobLen, + /* allowEmptyString */ true)) return Failure; D->FixIts.push_back(std::make_pair(SR, createCXString(RetStr, false))); continue; |