xref: /llvm-project/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp (revision 933b37f99f4f6f2ca3ab0d268caafc33c50bee84)
1 //===- SourceCoverageViewHTML.cpp - A html code coverage view -------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file This file implements the html coverage renderer.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #include "CoverageReport.h"
15 #include "SourceCoverageViewHTML.h"
16 #include "llvm/ADT/Optional.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/Support/FileSystem.h"
20 #include "llvm/Support/Format.h"
21 #include "llvm/Support/Path.h"
22 
23 using namespace llvm;
24 
25 namespace {
26 
27 // Return a string with the special characters in \p Str escaped.
28 std::string escape(StringRef Str, const CoverageViewOptions &Opts) {
29   std::string Result;
30   unsigned ColNum = 0; // Record the column number.
31   for (char C : Str) {
32     ++ColNum;
33     if (C == '&')
34       Result += "&";
35     else if (C == '<')
36       Result += "&lt;";
37     else if (C == '>')
38       Result += "&gt;";
39     else if (C == '\"')
40       Result += "&quot;";
41     else if (C == '\n' || C == '\r') {
42       Result += C;
43       ColNum = 0;
44     } else if (C == '\t') {
45       // Replace '\t' with TabSize spaces.
46       unsigned NumSpaces = Opts.TabSize - (--ColNum % Opts.TabSize);
47       for (unsigned I = 0; I < NumSpaces; ++I)
48         Result += "&nbsp;";
49       ColNum += NumSpaces;
50     } else
51       Result += C;
52   }
53   return Result;
54 }
55 
56 // Create a \p Name tag around \p Str, and optionally set its \p ClassName.
57 std::string tag(const std::string &Name, const std::string &Str,
58                 const std::string &ClassName = "") {
59   std::string Tag = "<" + Name;
60   if (ClassName != "")
61     Tag += " class='" + ClassName + "'";
62   return Tag + ">" + Str + "</" + Name + ">";
63 }
64 
65 // Create an anchor to \p Link with the label \p Str.
66 std::string a(const std::string &Link, const std::string &Str,
67               const std::string &TargetName = "") {
68   std::string Name = TargetName.empty() ? "" : ("name='" + TargetName + "' ");
69   return "<a " + Name + "href='" + Link + "'>" + Str + "</a>";
70 }
71 
72 const char *BeginHeader =
73   "<head>"
74     "<meta name='viewport' content='width=device-width,initial-scale=1'>"
75     "<meta charset='UTF-8'>";
76 
77 const char *CSSForCoverage =
78     R"(.red {
79   background-color: #ffd0d0;
80 }
81 .cyan {
82   background-color: cyan;
83 }
84 body {
85   font-family: -apple-system, sans-serif;
86 }
87 pre {
88   margin-top: 0px !important;
89   margin-bottom: 0px !important;
90 }
91 .source-name-title {
92   padding: 5px 10px;
93   border-bottom: 1px solid #dbdbdb;
94   background-color: #eee;
95   line-height: 35px;
96 }
97 .centered {
98   display: table;
99   margin-left: left;
100   margin-right: auto;
101   border: 1px solid #dbdbdb;
102   border-radius: 3px;
103 }
104 .expansion-view {
105   background-color: rgba(0, 0, 0, 0);
106   margin-left: 0px;
107   margin-top: 5px;
108   margin-right: 5px;
109   margin-bottom: 5px;
110   border: 1px solid #dbdbdb;
111   border-radius: 3px;
112 }
113 table {
114   border-collapse: collapse;
115 }
116 .light-row {
117   background: #ffffff;
118   border: 1px solid #dbdbdb;
119 }
120 .column-entry {
121   text-align: right;
122 }
123 .column-entry-left {
124   text-align: left;
125 }
126 .column-entry-yellow {
127   text-align: right;
128   background-color: #ffffd0;
129 }
130 .column-entry-red {
131   text-align: right;
132   background-color: #ffd0d0;
133 }
134 .column-entry-green {
135   text-align: right;
136   background-color: #d0ffd0;
137 }
138 .line-number {
139   text-align: right;
140   color: #aaa;
141 }
142 .covered-line {
143   text-align: right;
144   color: #0080ff;
145 }
146 .uncovered-line {
147   text-align: right;
148   color: #ff3300;
149 }
150 .tooltip {
151   position: relative;
152   display: inline;
153   background-color: #b3e6ff;
154   text-decoration: none;
155 }
156 .tooltip span.tooltip-content {
157   position: absolute;
158   width: 100px;
159   margin-left: -50px;
160   color: #FFFFFF;
161   background: #000000;
162   height: 30px;
163   line-height: 30px;
164   text-align: center;
165   visibility: hidden;
166   border-radius: 6px;
167 }
168 .tooltip span.tooltip-content:after {
169   content: '';
170   position: absolute;
171   top: 100%;
172   left: 50%;
173   margin-left: -8px;
174   width: 0; height: 0;
175   border-top: 8px solid #000000;
176   border-right: 8px solid transparent;
177   border-left: 8px solid transparent;
178 }
179 :hover.tooltip span.tooltip-content {
180   visibility: visible;
181   opacity: 0.8;
182   bottom: 30px;
183   left: 50%;
184   z-index: 999;
185 }
186 th, td {
187   vertical-align: top;
188   padding: 2px 5px;
189   border-collapse: collapse;
190   border-right: solid 1px #eee;
191   border-left: solid 1px #eee;
192 }
193 td:first-child {
194   border-left: none;
195 }
196 td:last-child {
197   border-right: none;
198 }
199 )";
200 
201 const char *EndHeader = "</head>";
202 
203 const char *BeginCenteredDiv = "<div class='centered'>";
204 
205 const char *EndCenteredDiv = "</div>";
206 
207 const char *BeginSourceNameDiv = "<div class='source-name-title'>";
208 
209 const char *EndSourceNameDiv = "</div>";
210 
211 const char *BeginCodeTD = "<td class='code'>";
212 
213 const char *EndCodeTD = "</td>";
214 
215 const char *BeginPre = "<pre>";
216 
217 const char *EndPre = "</pre>";
218 
219 const char *BeginExpansionDiv = "<div class='expansion-view'>";
220 
221 const char *EndExpansionDiv = "</div>";
222 
223 const char *BeginTable = "<table>";
224 
225 const char *EndTable = "</table>";
226 
227 const char *ProjectTitleTag = "h1";
228 
229 const char *ReportTitleTag = "h2";
230 
231 const char *CreatedTimeTag = "h4";
232 
233 std::string getPathToStyle(StringRef ViewPath) {
234   std::string PathToStyle = "";
235   std::string PathSep = sys::path::get_separator();
236   unsigned NumSeps = ViewPath.count(PathSep);
237   for (unsigned I = 0, E = NumSeps; I < E; ++I)
238     PathToStyle += ".." + PathSep;
239   return PathToStyle + "style.css";
240 }
241 
242 void emitPrelude(raw_ostream &OS, const CoverageViewOptions &Opts,
243                  const std::string &PathToStyle = "") {
244   OS << "<!doctype html>"
245         "<html>"
246      << BeginHeader;
247 
248   // Link to a stylesheet if one is available. Otherwise, use the default style.
249   if (PathToStyle.empty())
250     OS << "<style>" << CSSForCoverage << "</style>";
251   else
252     OS << "<link rel='stylesheet' type='text/css' href='"
253        << escape(PathToStyle, Opts) << "'>";
254 
255   OS << EndHeader << "<body>";
256 }
257 
258 void emitEpilog(raw_ostream &OS) {
259   OS << "</body>"
260      << "</html>";
261 }
262 
263 } // anonymous namespace
264 
265 Expected<CoveragePrinter::OwnedStream>
266 CoveragePrinterHTML::createViewFile(StringRef Path, bool InToplevel) {
267   auto OSOrErr = createOutputStream(Path, "html", InToplevel);
268   if (!OSOrErr)
269     return OSOrErr;
270 
271   OwnedStream OS = std::move(OSOrErr.get());
272 
273   if (!Opts.hasOutputDirectory()) {
274     emitPrelude(*OS.get(), Opts);
275   } else {
276     std::string ViewPath = getOutputPath(Path, "html", InToplevel);
277     emitPrelude(*OS.get(), Opts, getPathToStyle(ViewPath));
278   }
279 
280   return std::move(OS);
281 }
282 
283 void CoveragePrinterHTML::closeViewFile(OwnedStream OS) {
284   emitEpilog(*OS.get());
285 }
286 
287 /// Emit column labels for the table in the index.
288 static void emitColumnLabelsForIndex(raw_ostream &OS) {
289   SmallVector<std::string, 4> Columns;
290   Columns.emplace_back(tag("td", "Filename", "column-entry-left"));
291   for (const char *Label : {"Function Coverage", "Instantiation Coverage",
292                             "Line Coverage", "Region Coverage"})
293     Columns.emplace_back(tag("td", Label, "column-entry"));
294   OS << tag("tr", join(Columns.begin(), Columns.end(), ""));
295 }
296 
297 std::string
298 CoveragePrinterHTML::buildLinkToFile(StringRef SF,
299                                      const FileCoverageSummary &FCS) const {
300   SmallString<128> LinkTextStr(sys::path::relative_path(FCS.Name));
301   sys::path::remove_dots(LinkTextStr, /*remove_dot_dots=*/true);
302   sys::path::native(LinkTextStr);
303   std::string LinkText = escape(LinkTextStr, Opts);
304   std::string LinkTarget =
305       escape(getOutputPath(SF, "html", /*InToplevel=*/false), Opts);
306   return a(LinkTarget, LinkText);
307 }
308 
309 /// Render a file coverage summary (\p FCS) in a table row. If \p IsTotals is
310 /// false, link the summary to \p SF.
311 void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF,
312                                           const FileCoverageSummary &FCS,
313                                           bool IsTotals) const {
314   SmallVector<std::string, 8> Columns;
315 
316   // Format a coverage triple and add the result to the list of columns.
317   auto AddCoverageTripleToColumn = [&Columns](unsigned Hit, unsigned Total,
318                                               float Pctg) {
319     std::string S;
320     {
321       raw_string_ostream RSO{S};
322       if (Total)
323         RSO << format("%*.2f", 7, Pctg) << "% ";
324       else
325         RSO << "- ";
326       RSO << '(' << Hit << '/' << Total << ')';
327     }
328     const char *CellClass = "column-entry-yellow";
329     if (Hit == Total)
330       CellClass = "column-entry-green";
331     else if (Pctg < 80.0)
332       CellClass = "column-entry-red";
333     Columns.emplace_back(tag("td", tag("pre", S), CellClass));
334   };
335 
336   // Simplify the display file path, and wrap it in a link if requested.
337   std::string Filename;
338   if (IsTotals) {
339     Filename = "TOTALS";
340   } else {
341     Filename = buildLinkToFile(SF, FCS);
342   }
343 
344   Columns.emplace_back(tag("td", tag("pre", Filename)));
345   AddCoverageTripleToColumn(FCS.FunctionCoverage.Executed,
346                             FCS.FunctionCoverage.NumFunctions,
347                             FCS.FunctionCoverage.getPercentCovered());
348   AddCoverageTripleToColumn(FCS.InstantiationCoverage.Executed,
349                             FCS.InstantiationCoverage.NumFunctions,
350                             FCS.InstantiationCoverage.getPercentCovered());
351   AddCoverageTripleToColumn(FCS.LineCoverage.Covered, FCS.LineCoverage.NumLines,
352                             FCS.LineCoverage.getPercentCovered());
353   AddCoverageTripleToColumn(FCS.RegionCoverage.Covered,
354                             FCS.RegionCoverage.NumRegions,
355                             FCS.RegionCoverage.getPercentCovered());
356 
357   OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row");
358 }
359 
360 Error CoveragePrinterHTML::createIndexFile(
361     ArrayRef<std::string> SourceFiles,
362     const coverage::CoverageMapping &Coverage) {
363   // Emit the default stylesheet.
364   auto CSSOrErr = createOutputStream("style", "css", /*InToplevel=*/true);
365   if (Error E = CSSOrErr.takeError())
366     return E;
367 
368   OwnedStream CSS = std::move(CSSOrErr.get());
369   CSS->operator<<(CSSForCoverage);
370 
371   // Emit a file index along with some coverage statistics.
372   auto OSOrErr = createOutputStream("index", "html", /*InToplevel=*/true);
373   if (Error E = OSOrErr.takeError())
374     return E;
375   auto OS = std::move(OSOrErr.get());
376   raw_ostream &OSRef = *OS.get();
377 
378   assert(Opts.hasOutputDirectory() && "No output directory for index file");
379   emitPrelude(OSRef, Opts, getPathToStyle(""));
380 
381   // Emit some basic information about the coverage report.
382   if (Opts.hasProjectTitle())
383     OSRef << tag(ProjectTitleTag, escape(Opts.ProjectTitle, Opts));
384   OSRef << tag(ReportTitleTag, "Coverage Report");
385   if (Opts.hasCreatedTime())
386     OSRef << tag(CreatedTimeTag, escape(Opts.CreatedTimeStr, Opts));
387 
388   // Emit a link to some documentation.
389   OSRef << tag("p", "Click " +
390                         a("http://clang.llvm.org/docs/"
391                           "SourceBasedCodeCoverage.html#interpreting-reports",
392                           "here") +
393                         " for information about interpreting this report.");
394 
395   // Emit a table containing links to reports for each file in the covmapping.
396   // Exclude files which don't contain any regions.
397   OSRef << BeginCenteredDiv << BeginTable;
398   emitColumnLabelsForIndex(OSRef);
399   FileCoverageSummary Totals("TOTALS");
400   auto FileReports =
401       CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles);
402   bool EmptyFiles = false;
403   for (unsigned I = 0, E = FileReports.size(); I < E; ++I) {
404     if (FileReports[I].FunctionCoverage.NumFunctions)
405       emitFileSummary(OSRef, SourceFiles[I], FileReports[I]);
406     else
407       EmptyFiles = true;
408   }
409   emitFileSummary(OSRef, "Totals", Totals, /*IsTotals=*/true);
410   OSRef << EndTable << EndCenteredDiv;
411 
412   // Emit links to files which don't contain any functions. These are normally
413   // not very useful, but could be relevant for code which abuses the
414   // preprocessor.
415   if (EmptyFiles) {
416     OSRef << tag("p", "Files which contain no functions. (These "
417                       "files contain code pulled into other files "
418                       "by the preprocessor.)\n");
419     OSRef << BeginCenteredDiv << BeginTable;
420     for (unsigned I = 0, E = FileReports.size(); I < E; ++I)
421       if (!FileReports[I].FunctionCoverage.NumFunctions) {
422         std::string Link = buildLinkToFile(SourceFiles[I], FileReports[I]);
423         OSRef << tag("tr", tag("td", tag("pre", Link)), "light-row") << '\n';
424       }
425     OSRef << EndTable << EndCenteredDiv;
426   }
427 
428   OSRef << tag("h5", escape(Opts.getLLVMVersionString(), Opts));
429   emitEpilog(OSRef);
430 
431   return Error::success();
432 }
433 
434 void SourceCoverageViewHTML::renderViewHeader(raw_ostream &OS) {
435   OS << BeginCenteredDiv << BeginTable;
436 }
437 
438 void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) {
439   OS << EndTable << EndCenteredDiv;
440 }
441 
442 void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS, bool WholeFile) {
443   OS << BeginSourceNameDiv << tag("pre", escape(getSourceName(), getOptions()))
444      << EndSourceNameDiv;
445 }
446 
447 void SourceCoverageViewHTML::renderLinePrefix(raw_ostream &OS, unsigned) {
448   OS << "<tr>";
449 }
450 
451 void SourceCoverageViewHTML::renderLineSuffix(raw_ostream &OS, unsigned) {
452   // If this view has sub-views, renderLine() cannot close the view's cell.
453   // Take care of it here, after all sub-views have been rendered.
454   if (hasSubViews())
455     OS << EndCodeTD;
456   OS << "</tr>";
457 }
458 
459 void SourceCoverageViewHTML::renderViewDivider(raw_ostream &, unsigned) {
460   // The table-based output makes view dividers unnecessary.
461 }
462 
463 void SourceCoverageViewHTML::renderLine(
464     raw_ostream &OS, LineRef L, const coverage::CoverageSegment *WrappedSegment,
465     CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned) {
466   StringRef Line = L.Line;
467   unsigned LineNo = L.LineNo;
468 
469   // Steps for handling text-escaping, highlighting, and tooltip creation:
470   //
471   // 1. Split the line into N+1 snippets, where N = |Segments|. The first
472   //    snippet starts from Col=1 and ends at the start of the first segment.
473   //    The last snippet starts at the last mapped column in the line and ends
474   //    at the end of the line. Both are required but may be empty.
475 
476   SmallVector<std::string, 8> Snippets;
477 
478   unsigned LCol = 1;
479   auto Snip = [&](unsigned Start, unsigned Len) {
480     Snippets.push_back(Line.substr(Start, Len));
481     LCol += Len;
482   };
483 
484   Snip(LCol - 1, Segments.empty() ? 0 : (Segments.front()->Col - 1));
485 
486   for (unsigned I = 1, E = Segments.size(); I < E; ++I)
487     Snip(LCol - 1, Segments[I]->Col - LCol);
488 
489   // |Line| + 1 is needed to avoid underflow when, e.g |Line| = 0 and LCol = 1.
490   Snip(LCol - 1, Line.size() + 1 - LCol);
491 
492   // 2. Escape all of the snippets.
493 
494   for (unsigned I = 0, E = Snippets.size(); I < E; ++I)
495     Snippets[I] = escape(Snippets[I], getOptions());
496 
497   // 3. Use \p WrappedSegment to set the highlight for snippet 0. Use segment
498   //    1 to set the highlight for snippet 2, segment 2 to set the highlight for
499   //    snippet 3, and so on.
500 
501   Optional<std::string> Color;
502   SmallVector<std::pair<unsigned, unsigned>, 2> HighlightedRanges;
503   auto Highlight = [&](const std::string &Snippet, unsigned LC, unsigned RC) {
504     if (getOptions().Debug)
505       HighlightedRanges.emplace_back(LC, RC);
506     return tag("span", Snippet, Color.getValue());
507   };
508 
509   auto CheckIfUncovered = [](const coverage::CoverageSegment *S) {
510     return S && S->HasCount && S->Count == 0;
511   };
512 
513   if (CheckIfUncovered(WrappedSegment)) {
514     Color = "red";
515     if (!Snippets[0].empty())
516       Snippets[0] = Highlight(Snippets[0], 1, 1 + Snippets[0].size());
517   }
518 
519   for (unsigned I = 0, E = Segments.size(); I < E; ++I) {
520     const auto *CurSeg = Segments[I];
521     if (CurSeg->Col == ExpansionCol)
522       Color = "cyan";
523     else if (CheckIfUncovered(CurSeg))
524       Color = "red";
525     else
526       Color = None;
527 
528     if (Color.hasValue())
529       Snippets[I + 1] = Highlight(Snippets[I + 1], CurSeg->Col,
530                                   CurSeg->Col + Snippets[I + 1].size());
531   }
532 
533   if (Color.hasValue() && Segments.empty())
534     Snippets.back() = Highlight(Snippets.back(), 1, 1 + Snippets.back().size());
535 
536   if (getOptions().Debug) {
537     for (const auto &Range : HighlightedRanges) {
538       errs() << "Highlighted line " << LineNo << ", " << Range.first << " -> ";
539       if (Range.second == 0)
540         errs() << "?";
541       else
542         errs() << Range.second;
543       errs() << "\n";
544     }
545   }
546 
547   // 4. Snippets[1:N+1] correspond to \p Segments[0:N]: use these to generate
548   //    sub-line region count tooltips if needed.
549 
550   if (shouldRenderRegionMarkers(Segments)) {
551     // Just consider the segments which start *and* end on this line.
552     for (unsigned I = 0, E = Segments.size() - 1; I < E; ++I) {
553       const auto *CurSeg = Segments[I];
554       if (!CurSeg->IsRegionEntry)
555         continue;
556 
557       Snippets[I + 1] =
558           tag("div", Snippets[I + 1] + tag("span", formatCount(CurSeg->Count),
559                                            "tooltip-content"),
560               "tooltip");
561 
562       if (getOptions().Debug)
563         errs() << "Marker at " << CurSeg->Line << ":" << CurSeg->Col << " = "
564                << formatCount(CurSeg->Count) << "\n";
565     }
566   }
567 
568   OS << BeginCodeTD;
569   OS << BeginPre;
570   for (const auto &Snippet : Snippets)
571     OS << Snippet;
572   OS << EndPre;
573 
574   // If there are no sub-views left to attach to this cell, end the cell.
575   // Otherwise, end it after the sub-views are rendered (renderLineSuffix()).
576   if (!hasSubViews())
577     OS << EndCodeTD;
578 }
579 
580 void SourceCoverageViewHTML::renderLineCoverageColumn(
581     raw_ostream &OS, const LineCoverageStats &Line) {
582   std::string Count = "";
583   if (Line.isMapped())
584     Count = tag("pre", formatCount(Line.ExecutionCount));
585   std::string CoverageClass =
586       (Line.ExecutionCount > 0) ? "covered-line" : "uncovered-line";
587   OS << tag("td", Count, CoverageClass);
588 }
589 
590 void SourceCoverageViewHTML::renderLineNumberColumn(raw_ostream &OS,
591                                                     unsigned LineNo) {
592   std::string LineNoStr = utostr(uint64_t(LineNo));
593   std::string TargetName = "L" + LineNoStr;
594   OS << tag("td", a("#" + TargetName, tag("pre", LineNoStr), TargetName),
595             "line-number");
596 }
597 
598 void SourceCoverageViewHTML::renderRegionMarkers(raw_ostream &,
599                                                  CoverageSegmentArray,
600                                                  unsigned) {
601   // Region markers are rendered in-line using tooltips.
602 }
603 
604 void SourceCoverageViewHTML::renderExpansionSite(
605     raw_ostream &OS, LineRef L, const coverage::CoverageSegment *WrappedSegment,
606     CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned ViewDepth) {
607   // Render the line containing the expansion site. No extra formatting needed.
608   renderLine(OS, L, WrappedSegment, Segments, ExpansionCol, ViewDepth);
609 }
610 
611 void SourceCoverageViewHTML::renderExpansionView(raw_ostream &OS,
612                                                  ExpansionView &ESV,
613                                                  unsigned ViewDepth) {
614   OS << BeginExpansionDiv;
615   ESV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/false,
616                   ViewDepth + 1);
617   OS << EndExpansionDiv;
618 }
619 
620 void SourceCoverageViewHTML::renderInstantiationView(raw_ostream &OS,
621                                                      InstantiationView &ISV,
622                                                      unsigned ViewDepth) {
623   OS << BeginExpansionDiv;
624   if (!ISV.View)
625     OS << BeginSourceNameDiv
626        << tag("pre",
627               escape("Unexecuted instantiation: " + ISV.FunctionName.str(),
628                      getOptions()))
629        << EndSourceNameDiv;
630   else
631     ISV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/true,
632                     ViewDepth);
633   OS << EndExpansionDiv;
634 }
635 
636 void SourceCoverageViewHTML::renderTitle(raw_ostream &OS, StringRef Title) {
637   if (getOptions().hasProjectTitle())
638     OS << tag(ProjectTitleTag, escape(getOptions().ProjectTitle, getOptions()));
639   OS << tag(ReportTitleTag, escape(Title, getOptions()));
640   if (getOptions().hasCreatedTime())
641     OS << tag(CreatedTimeTag,
642               escape(getOptions().CreatedTimeStr, getOptions()));
643 }
644 
645 void SourceCoverageViewHTML::renderTableHeader(raw_ostream &OS,
646                                                unsigned FirstUncoveredLineNo,
647                                                unsigned ViewDepth) {
648   std::string SourceLabel;
649   if (FirstUncoveredLineNo == 0) {
650     SourceLabel = tag("td", tag("pre", "Source"));
651   } else {
652     std::string LinkTarget = "#L" + utostr(uint64_t(FirstUncoveredLineNo));
653     SourceLabel =
654         tag("td", tag("pre", "Source (" +
655                                  a(LinkTarget, "jump to first uncovered line") +
656                                  ")"));
657   }
658 
659   renderLinePrefix(OS, ViewDepth);
660   OS << tag("td", tag("pre", "Line")) << tag("td", tag("pre", "Count"))
661      << SourceLabel;
662   renderLineSuffix(OS, ViewDepth);
663 }
664