Index: test/tools/llvm-cov/Inputs/noZeroExecutionLine.proftext =================================================================== --- /dev/null +++ test/tools/llvm-cov/Inputs/noZeroExecutionLine.proftext @@ -0,0 +1,9 @@ +main +# Func Hash: +4 +# Num Counters: +2 +# Counter Values: +1 +10 + Index: test/tools/llvm-cov/noZeroExecutionLine.cpp =================================================================== --- /dev/null +++ test/tools/llvm-cov/noZeroExecutionLine.cpp @@ -0,0 +1,16 @@ +// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/noZeroExecutionLine.proftext +// RUN: llvm-cov show %S/Inputs/noZeroExecutionLine.covmapping -instr-profile %t.profdata -filename-equivalence -format html -output-dir %t.dir %s +// RUN: FileCheck -check-prefix=CHECK -check-prefix=WHOLE-FILE -input-file %t.dir/coverage/tmp/noZeroExecutionLine.cpp.html %s + +int main(int argc, char ** argv) { + int x=0; + for (int i = 0; i < 10; ++i) + x *= 2; + return x; +} + +// CHECK: Goto first zero count +// CHECK-NOT: +// CHECK: "; + +// Define a javascript function that disables a hyper link. +const char *JSDisableLink = R"( +function disableLink(link) { + link.disabled = true; + link.removeAttribute('href'); +} +)"; + +// Return a string with the special characters in \p Str escaped. +const char *JSRemoveZeroLink = R"( +var zeroLink = document.getElementById("zeroline"); +disableLink(zeroLink); +)"; + std::string getPathToStyle(StringRef ViewPath) { std::string PathToStyle = ""; std::string PathSep = sys::path::get_separator(); @@ -331,8 +349,11 @@ OS << LineBreak << BeginCenteredDiv << BeginTable; } -void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) { +void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS, + bool renderJavaScript) { OS << EndTable << EndCenteredDiv; + if (renderJavaScript) + OS << BeginJavaScript << JSDisableLink << JSRemoveZeroLink << EndJavaScript; } void SourceCoverageViewHTML::renderObjectFilename(raw_ostream &OS) { @@ -342,6 +363,11 @@ OS << tag("pre", escape(ObjectFile.c_str(), getOptions())); } +void SourceCoverageViewHTML::renderGotoFirstZero(raw_ostream &OS) { + OS << BeginPre << " " + << "Goto first zero count" << EndPre; +} + void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS, bool WholeFile) { OS << BeginSourceNameDiv; // Render the source name for the view. @@ -350,13 +376,16 @@ : "Source file: " + SourceFile; OS << tag("pre", escape(SourceFile, getOptions())); // Render the object file name for the view. - if (WholeFile) + if (WholeFile) { renderObjectFilename(OS); + renderGotoFirstZero(OS); + } OS << EndSourceNameDiv; } -void SourceCoverageViewHTML::renderLinePrefix(raw_ostream &OS, unsigned) { - OS << ""; +void SourceCoverageViewHTML::renderLinePrefix(raw_ostream &OS, unsigned, + bool IsFirstZeroLine = false) { + OS << (IsFirstZeroLine ? "" : ""); } void SourceCoverageViewHTML::renderLineSuffix(raw_ostream &OS, unsigned) { Index: tools/llvm-cov/SourceCoverageViewText.h =================================================================== --- tools/llvm-cov/SourceCoverageViewText.h +++ tools/llvm-cov/SourceCoverageViewText.h @@ -36,13 +36,13 @@ class SourceCoverageViewText : public SourceCoverageView { void renderViewHeader(raw_ostream &OS) override; - void renderViewFooter(raw_ostream &OS) override; + void renderViewFooter(raw_ostream &OS, bool renderJavaScript) override; void renderObjectFilename(raw_ostream &OS) override; void renderSourceName(raw_ostream &OS, bool WholeFile) override; - void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth) override; + void renderLinePrefix(raw_ostream &OS, unsigned ViewDepth, bool IsFirstZeroLine) override; void renderLineSuffix(raw_ostream &OS, unsigned ViewDepth) override; Index: tools/llvm-cov/SourceCoverageViewText.cpp =================================================================== --- tools/llvm-cov/SourceCoverageViewText.cpp +++ tools/llvm-cov/SourceCoverageViewText.cpp @@ -61,7 +61,8 @@ void SourceCoverageViewText::renderViewHeader(raw_ostream &) {} -void SourceCoverageViewText::renderViewFooter(raw_ostream &) {} +void SourceCoverageViewText::renderViewFooter(raw_ostream &, + bool renderJavaScript) {} void SourceCoverageViewText::renderObjectFilename(raw_ostream &OS) { getOptions().colored_ostream(OS, raw_ostream::CYAN) @@ -76,7 +77,8 @@ } void SourceCoverageViewText::renderLinePrefix(raw_ostream &OS, - unsigned ViewDepth) { + unsigned ViewDepth, + bool IsFirstZeroLine = false) { for (unsigned I = 0; I < ViewDepth; ++I) OS << " |"; }