From 38d50545feb7faffec8b8bbbb40661d21babf6af Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Tue, 30 Oct 2018 18:41:31 +0000 Subject: [PATCH] [GCOV] Function counters are wrong when on one line Summary: After commit https://reviews.llvm.org/rL344228, the function definitions have a counter but when on one line the counter is wrong (e.g. void foo() { }) I added a test in: https://reviews.llvm.org/D53601 Reviewers: marco-c Reviewed By: marco-c Subscribers: llvm-commits, sylvestre.ledru Differential Revision: https://reviews.llvm.org/D53600 llvm-svn: 345624 --- llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp index ee546a9..01938a0 100644 --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -572,9 +572,8 @@ void GCOVProfiler::emitProfileNotes() { // Add the function line number to the lines of the entry block // to have a counter for the function definition. - Func.getBlock(&EntryBlock) - .getFile(SP->getFilename()) - .addLine(SP->getLine()); + uint32_t Line = SP->getLine(); + Func.getBlock(&EntryBlock).getFile(SP->getFilename()).addLine(Line); for (auto &BB : F) { GCOVBlock &Block = Func.getBlock(&BB); @@ -587,7 +586,6 @@ void GCOVProfiler::emitProfileNotes() { Block.addEdge(Func.getReturnBlock()); } - uint32_t Line = 0; for (auto &I : BB) { // Debug intrinsic locations correspond to the location of the // declaration, not necessarily any statements or expressions. @@ -609,6 +607,7 @@ void GCOVProfiler::emitProfileNotes() { GCOVLines &Lines = Block.getFile(SP->getFilename()); Lines.addLine(Loc.getLine()); } + Line = 0; } EdgeDestinations += Func.getEdgeDestinations(); } -- 2.7.4