Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 6b2b204

Browse files
committed
Check whether functions have any lines associated before emitting coverage info for them. This isn't just a size/time saving, gcov may crash on these.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206671 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent aae82fb commit 6b2b204

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/Transforms/Instrumentation/GCOVProfiling.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,21 @@ bool GCOVProfiler::runOnModule(Module &M) {
449449
return false;
450450
}
451451

452+
static bool functionHasLines(Function *F) {
453+
// Check whether this function actually has any source lines. Not only
454+
// do these waste space, they also can crash gcov.
455+
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
456+
for (BasicBlock::iterator I = BB->begin(), IE = BB->end();
457+
I != IE; ++I) {
458+
const DebugLoc &Loc = I->getDebugLoc();
459+
if (Loc.isUnknown()) continue;
460+
if (Loc.getLine() != 0)
461+
return true;
462+
}
463+
}
464+
return false;
465+
}
466+
452467
void GCOVProfiler::emitProfileNotes() {
453468
NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu");
454469
if (!CU_Nodes) return;
@@ -474,6 +489,7 @@ void GCOVProfiler::emitProfileNotes() {
474489

475490
Function *F = SP.getFunction();
476491
if (!F) continue;
492+
if (!functionHasLines(F)) continue;
477493

478494
// gcov expects every function to start with an entry block that has a
479495
// single successor, so split the entry block to make sure of that.
@@ -549,6 +565,7 @@ bool GCOVProfiler::emitProfileArcs() {
549565
continue;
550566
Function *F = SP.getFunction();
551567
if (!F) continue;
568+
if (!functionHasLines(F)) continue;
552569
if (!Result) Result = true;
553570
unsigned Edges = 0;
554571
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {

0 commit comments

Comments
 (0)