@@ -449,6 +449,21 @@ bool GCOVProfiler::runOnModule(Module &M) {
449
449
return false ;
450
450
}
451
451
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
+
452
467
void GCOVProfiler::emitProfileNotes () {
453
468
NamedMDNode *CU_Nodes = M->getNamedMetadata (" llvm.dbg.cu" );
454
469
if (!CU_Nodes) return ;
@@ -474,6 +489,7 @@ void GCOVProfiler::emitProfileNotes() {
474
489
475
490
Function *F = SP.getFunction ();
476
491
if (!F) continue ;
492
+ if (!functionHasLines (F)) continue ;
477
493
478
494
// gcov expects every function to start with an entry block that has a
479
495
// single successor, so split the entry block to make sure of that.
@@ -549,6 +565,7 @@ bool GCOVProfiler::emitProfileArcs() {
549
565
continue ;
550
566
Function *F = SP.getFunction ();
551
567
if (!F) continue ;
568
+ if (!functionHasLines (F)) continue ;
552
569
if (!Result) Result = true ;
553
570
unsigned Edges = 0 ;
554
571
for (Function::iterator BB = F->begin (), E = F->end (); BB != E; ++BB) {
0 commit comments