[PATCH] D16212: Fix reading gcov data that does not have function names

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 8 09:58:19 PST 2016


Arseny Kapoulkine <arseny.kapoulkine at gmail.com> writes:
> arseny.kapoulkine updated this revision to Diff 45946.
> arseny.kapoulkine added a comment.
>
> Updated the diff to use "have we read the entire chunk" as a condition
> so that we don't have to track the required length specifically. Also
> added a test (compiled with clang with options that make the output
> gcov-compatible).

Looks good. Do you need me to commit this for you?

>
> http://reviews.llvm.org/D16212
>
> Files:
>   lib/IR/GCOV.cpp
>   test/tools/llvm-cov/Inputs/gcov_compatibility.gcda
>   test/tools/llvm-cov/Inputs/gcov_compatibility.gcno
>   test/tools/llvm-cov/gcov_compatibility.cpp
>
> 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
> 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()) {


More information about the llvm-commits mailing list