Index: lib/IR/GCOV.cpp =================================================================== --- lib/IR/GCOV.cpp +++ lib/IR/GCOV.cpp @@ -247,10 +247,12 @@ /// readGCDA - Read a function from the GCDA buffer. Return false if an error /// occurs. bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { - uint32_t Dummy; - if (!Buff.readInt(Dummy)) + uint32_t HeaderLength; + if (!Buff.readInt(HeaderLength)) return false; // Function header length + uint64_t EndPos = Buff.getCursor() + HeaderLength * sizeof(uint32_t); + uint32_t GCDAIdent; if (!Buff.readInt(GCDAIdent)) return false; @@ -280,13 +282,15 @@ } } - StringRef GCDAName; - if (!Buff.readString(GCDAName)) - return false; - if (Name != GCDAName) { - errs() << "Function names do not match: " << Name << " != " << GCDAName - << ".\n"; - return false; + if (Buff.getCursor() < EndPos) { + StringRef GCDAName; + if (!Buff.readString(GCDAName)) + return false; + if (Name != GCDAName) { + errs() << "Function names do not match: " << Name << " != " << GCDAName + << ".\n"; + return false; + } } if (!Buff.readArcTag()) { Index: test/tools/llvm-cov/gcov_compatibility.cpp =================================================================== --- /dev/null +++ test/tools/llvm-cov/gcov_compatibility.cpp @@ -0,0 +1,30 @@ +// Make sure that llvm-cov can read coverage data written in gcov-compatible +// format. + +// Compile with these arguments and run the result to generate .gc* files: +// -coverage -Xclang -coverage-no-function-names-in-data +// -Xclang -coverage-cfg-checksum -Xclang -coverage-version='407*' + +// We need shell for cd +// REQUIRES: shell + +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: cd %t +// RUN: cp %s %p/Inputs/gcov_compatibility.gc* . + +// RUN: llvm-cov gcov gcov_compatibility.cpp | FileCheck %s --check-prefix=STDOUT +// STDOUT: File 'gcov_compatibility.cpp' +// STDOUT: Lines executed:100.00% of 1 +// STDOUT: gcov_compatibility.cpp:creating 'gcov_compatibility.cpp.gcov' + +// RUN: FileCheck %s --check-prefix=GCOV < %t/gcov_compatibility.cpp.gcov +// GCOV: -: 0:Runs:1 +// GCOV: -: 0:Programs:1 + +int main(int argc, const char *argv[]) { // GCOV: -: [[@LINE]]:int main( + return 0; // GCOV: 1: [[@LINE]]: return +} // GCOV: -: [[@LINE]]:} + +// llvm-cov doesn't work on big endian yet +// XFAIL: powerpc64-, s390x, mips-, mips64-, sparc