From 59aecc1cf0b45744b51a2e960a63a3de33adeb0d Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Thu, 5 Jun 2014 04:31:43 +0000 Subject: [PATCH] Fix coverage for files with global constructors again. Adds a testcase to the commit from r206671, as requested by David Blaikie. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210239 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Instrumentation/GCOVProfiling.cpp | 10 ++++ test/Transforms/GCOVProfiling/global-ctor.ll | 58 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 test/Transforms/GCOVProfiling/global-ctor.ll diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 583a0944689..cfeb62eb1f9 100644 --- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -457,8 +457,13 @@ static bool functionHasLines(Function *F) { // Debug intrinsic locations correspond to the location of the // declaration, not necessarily any statements or expressions. if (isa(I)) continue; + const DebugLoc &Loc = I->getDebugLoc(); if (Loc.isUnknown()) continue; + + // Artificial lines such as calls to the global constructors. + if (Loc.getLine() == 0) continue; + return true; } } @@ -521,8 +526,13 @@ void GCOVProfiler::emitProfileNotes() { // Debug intrinsic locations correspond to the location of the // declaration, not necessarily any statements or expressions. if (isa(I)) continue; + const DebugLoc &Loc = I->getDebugLoc(); if (Loc.isUnknown()) continue; + + // Artificial lines such as calls to the global constructors. + if (Loc.getLine() == 0) continue; + if (Line == Loc.getLine()) continue; Line = Loc.getLine(); if (SP != getDISubprogram(Loc.getScope(*Ctx))) continue; diff --git a/test/Transforms/GCOVProfiling/global-ctor.ll b/test/Transforms/GCOVProfiling/global-ctor.ll new file mode 100644 index 00000000000..722a0962ec5 --- /dev/null +++ b/test/Transforms/GCOVProfiling/global-ctor.ll @@ -0,0 +1,58 @@ +; RUN: echo '!16 = metadata !{metadata !"%T/global-ctor.ll", metadata !0}' > %t1 +; RUN: cat %s %t1 > %t2 +; RUN: opt -insert-gcov-profiling -disable-output < %t2 +; RUN: not grep '_GLOBAL__sub_I_global-ctor' %T/global-ctor.gcno +; RUN: rm %T/global-ctor.gcno + +; REQUIRES: shell + +@x = global i32 0, align 4 +@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_global-ctor.ll, i8* null }] + +; Function Attrs: nounwind +define internal void @__cxx_global_var_init() #0 section ".text.startup" { +entry: + br label %0 + +;