Correctly handle reading locations from serialized diagnostics
authorJustin Bogner <mail@justinbogner.com>
Fri, 10 Oct 2014 22:20:26 +0000 (22:20 +0000)
committerJustin Bogner <mail@justinbogner.com>
Fri, 10 Oct 2014 22:20:26 +0000 (22:20 +0000)
When reading a serialized diagnostic location with no file ID, we were
failing to increment the cursor past the rest of the location. This
would lead to the flags and category always appearing blank in such
diagnostics.

This changes the function to unconditionally increment the cursor and
updates the test to check for the correct output instead of testing
that we were doing this wrong. I've also updated the error check to
check for the correct number of fields.

llvm-svn: 219538

clang/test/Misc/serialized-diags.m
clang/tools/libclang/CXLoadedDiagnostic.cpp

index aac791e..71c983b 100644 (file)
@@ -21,7 +21,7 @@
 // CHECK: Range: {{.*[/\\]}}serialized-diags.m:8:4 {{.*[/\\]}}serialized-diags.m:8:9
 // CHECK: Number FIXITs = 1
 // CHECK: FIXIT: ({{.*[/\\]}}serialized-diags.m:8:4 - {{.*[/\\]}}serialized-diags.m:8:9): "self"
-// CHECK: +-(null):0:0: note: 'self' is an implicit parameter [] []
+// CHECK: +-(null):0:0: note: 'self' is an implicit parameter [] [Semantic Issue]
 // CHECK: Number FIXITs = 0
 // CHECK: {{.*[/\\]}}serialized-diags.m:1:12: warning: class 'Foo' defined without specifying a base class [-Wobjc-root-class] [Semantic Issue]
 // CHECK: Number FIXITs = 0
index df8f414..0e0075f 100644 (file)
@@ -485,12 +485,14 @@ LoadResult DiagLoader::readString(CXLoadedDiagnosticSetImpl &TopDiags,
 LoadResult DiagLoader::readLocation(CXLoadedDiagnosticSetImpl &TopDiags,
                                     RecordData &Record, unsigned &offset,
                                     CXLoadedDiagnostic::Location &Loc) {
-  if (Record.size() < offset + 3) {
+  if (Record.size() < offset + 4) {
     reportInvalidFile("Corrupted source location");
     return Failure;
   }
+  auto Fields = makeArrayRef(Record).slice(offset);
+  offset += 4;
   
-  unsigned fileID = Record[offset++];
+  unsigned fileID = Fields[0];
   if (fileID == 0) {
     // Sentinel value.
     Loc.file = nullptr;
@@ -506,9 +508,9 @@ LoadResult DiagLoader::readLocation(CXLoadedDiagnosticSetImpl &TopDiags,
     return Failure;
   }
   Loc.file = const_cast<FileEntry *>(FE);
-  Loc.line = Record[offset++];
-  Loc.column = Record[offset++];
-  Loc.offset = Record[offset++];
+  Loc.line = Fields[1];
+  Loc.column = Fields[2];
+  Loc.offset = Fields[3];
   return Success;
 }