summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorYuchen Wu <yuchenericwu@hotmail.com>2013-10-24 01:51:04 +0000
committerYuchen Wu <yuchenericwu@hotmail.com>2013-10-24 01:51:04 +0000
commit887c20ffc2691c26be081da69fb8844cdbf63832 (patch)
treefe9526c2397d5b1075458c5a991ea515682b3cb6 /llvm/lib/IR
parentb32b95d814704b1e1a13240ab74d5a4b6f5594cb (diff)
downloadbcm5719-llvm-887c20ffc2691c26be081da69fb8844cdbf63832.tar.gz
bcm5719-llvm-887c20ffc2691c26be081da69fb8844cdbf63832.zip
Fixed llvm-cov to count edges instead of blocks.
This was a fundamental flaw in llvm-cov where it treated the values in the GCDA files as block counts instead of edge counts. This created incorrect line counts when branching was present. Instead, the edge counts should be summed to obtain the correct block count. The fix was tested using custom test files as well as single source files from the test-suite directory. The behaviour can be verified by reading the GCOV documentation that describes the GCDA spec ("ARC_COUNTS gives the counter values for those arcs that are instrumented") and the header description provided by GCOVProfiling.cpp ("instruments the code that runs to records (sic) the edges between blocks that run and emit a complementary "gcda" file on exit"). llvm-svn: 193299
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/GCOV.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/IR/GCOV.cpp b/llvm/lib/IR/GCOV.cpp
index 68b91e6dc9a..908523a3a66 100644
--- a/llvm/lib/IR/GCOV.cpp
+++ b/llvm/lib/IR/GCOV.cpp
@@ -103,9 +103,18 @@ bool GCOVFunction::read(GCOVBuffer &Buff, GCOV::GCOVFormat Format) {
if (Format == GCOV::GCDA_402 || Format == GCOV::GCDA_404) {
Buff.readArcTag();
+ uint32_t i = 0;
uint32_t Count = Buff.readInt() / 2;
- for (unsigned i = 0, e = Count; i != e; ++i) {
- Blocks[i]->addCount(Buff.readInt64());
+
+ // This for loop adds the counts for each block. A second nested loop is
+ // required to combine the edge counts that are contained in the GCDA file.
+ for (uint32_t Line = 0; i < Count; ++Line) {
+ GCOVBlock &Block = *Blocks[Line];
+ for (size_t Edge = 0, End = Block.getNumEdges(); Edge < End; ++Edge) {
+ assert(i < Count && "Unexpected number of Edges!");
+ Block.addCount(Buff.readInt64());
+ ++i;
+ }
}
return true;
}
OpenPOWER on IntegriCloud