From 5f53ddd0cc284061519c40e0b98cf124db3674fb Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 3 Jun 2014 04:25:36 +0000 Subject: [PATCH] Ignore line numbers on debug intrinsics. Add an assert to ensure that we aren't emitting line number zero, the .gcno format uses this to indicate that the next field is a filename. llvm-svn: 210068 --- .../Transforms/Instrumentation/GCOVProfiling.cpp | 6 +- llvm/test/Transforms/GCOVProfiling/linezero.ll | 143 +++++++++++++++++++++ 2 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 llvm/test/Transforms/GCOVProfiling/linezero.ll diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 8330a9b..1dfe588 100644 --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -211,6 +211,7 @@ namespace { class GCOVLines : public GCOVRecord { public: void addLine(uint32_t Line) { + assert(Line != 0 && "Line zero is not a valid real line number."); Lines.push_back(Line); } @@ -453,10 +454,10 @@ static bool functionHasLines(Function *F) { for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { for (BasicBlock::iterator I = BB->begin(), IE = BB->end(); I != IE; ++I) { + if (isa(I)) continue; const DebugLoc &Loc = I->getDebugLoc(); if (Loc.isUnknown()) continue; - if (Loc.getLine() != 0) - return true; + return true; } } return false; @@ -515,6 +516,7 @@ void GCOVProfiler::emitProfileNotes() { uint32_t Line = 0; for (BasicBlock::iterator I = BB->begin(), IE = BB->end(); I != IE; ++I) { + if (isa(I)) continue; const DebugLoc &Loc = I->getDebugLoc(); if (Loc.isUnknown()) continue; if (Line == Loc.getLine()) continue; diff --git a/llvm/test/Transforms/GCOVProfiling/linezero.ll b/llvm/test/Transforms/GCOVProfiling/linezero.ll new file mode 100644 index 0000000..e2f8324 --- /dev/null +++ b/llvm/test/Transforms/GCOVProfiling/linezero.ll @@ -0,0 +1,143 @@ +; RUN: sed -e 's@PATTERN@\%T@g' < %s > %t1 +; RUN: opt -insert-gcov-profiling -disable-output < %t1 +; RUN: rm %T/linezero.gcno %t1 +; REQUIRES: shell + +; This is a crash test. + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%struct.vector = type { i8 } + +; Function Attrs: nounwind +define i32 @_Z4testv() #0 { +entry: + %retval = alloca i32, align 4 + %__range = alloca %struct.vector*, align 8 + %ref.tmp = alloca %struct.vector, align 1 + %undef.agg.tmp = alloca %struct.vector, align 1 + %__begin = alloca i8*, align 8 + %__end = alloca i8*, align 8 + %spec = alloca i8, align 1 + call void @llvm.dbg.declare(metadata !{%struct.vector** %__range}, metadata !27), !dbg !30 + br label %0 + +;