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
diff --git a/tools/libclang/CXLoadedDiagnostic.cpp b/tools/libclang/CXLoadedDiagnostic.cpp
index 510f617..61b9e33 100644
--- a/tools/libclang/CXLoadedDiagnostic.cpp
+++ b/tools/libclang/CXLoadedDiagnostic.cpp
@@ -220,14 +220,16 @@
                         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 @@
                                   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 @@
                       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 @@
                                   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 @@
         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;