From 62136e45499812f005a012443ad0bed920a91628 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Fri, 10 Oct 2014 22:20:26 +0000 Subject: [PATCH] Correctly handle reading locations from serialized diagnostics 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219538 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Misc/serialized-diags.m | 2 +- tools/libclang/CXLoadedDiagnostic.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test/Misc/serialized-diags.m b/test/Misc/serialized-diags.m index aac791e9e2..71c983b883 100644 --- a/test/Misc/serialized-diags.m +++ b/test/Misc/serialized-diags.m @@ -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 diff --git a/tools/libclang/CXLoadedDiagnostic.cpp b/tools/libclang/CXLoadedDiagnostic.cpp index df8f41440e..0e0075fc38 100644 --- a/tools/libclang/CXLoadedDiagnostic.cpp +++ b/tools/libclang/CXLoadedDiagnostic.cpp @@ -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(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; } -- 2.40.0