From 60b571e49a90d38697b3aca23020d9da42fc7d7f Mon Sep 17 00:00:00 2001 From: dim Date: Sun, 2 Apr 2017 17:24:58 +0000 Subject: Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release: MFC r309142 (by emaste): Add WITH_LLD_AS_LD build knob If set it installs LLD as /usr/bin/ld. LLD (as of version 3.9) is not capable of linking the world and kernel, but can self-host and link many substantial applications. GNU ld continues to be used for the world and kernel build, regardless of how this knob is set. It is on by default for arm64, and off for all other CPU architectures. Sponsored by: The FreeBSD Foundation MFC r310840: Reapply 310775, now it also builds correctly if lldb is disabled: Move llvm-objdump from CLANG_EXTRAS to installed by default We currently install three tools from binutils 2.17.50: as, ld, and objdump. Work is underway to migrate to a permissively-licensed tool-chain, with one goal being the retirement of binutils 2.17.50. LLVM's llvm-objdump is intended to be compatible with GNU objdump although it is currently missing some options and may have formatting differences. Enable it by default for testing and further investigation. It may later be changed to install as /usr/bin/objdump, it becomes a fully viable replacement. Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D8879 MFC r312855 (by emaste): Rename LLD_AS_LD to LLD_IS_LD, for consistency with CLANG_IS_CC Reported by: Dan McGregor MFC r313559 | glebius | 2017-02-10 18:34:48 +0100 (Fri, 10 Feb 2017) | 5 lines Don't check struct rtentry on FreeBSD, it is an internal kernel structure. On other systems it may be API structure for SIOCADDRT/SIOCDELRT. Reviewed by: emaste, dim MFC r314152 (by jkim): Remove an assembler flag, which is redundant since r309124. The upstream took care of it by introducing a macro NO_EXEC_STACK_DIRECTIVE. http://llvm.org/viewvc/llvm-project?rev=273500&view=rev Reviewed by: dim MFC r314564: Upgrade our copies of clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 (branches/release_40 296509). The release will follow soon. Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11 support to build; see UPDATING for more information. Also note that as of 4.0.0, lld should be able to link the base system on amd64 and aarch64. See the WITH_LLD_IS_LLD setting in src.conf(5). Though please be aware that this is work in progress. Release notes for llvm, clang and lld will be available here: Thanks to Ed Maste, Jan Beich, Antoine Brodin and Eric Fiselier for their help. Relnotes: yes Exp-run: antoine PR: 215969, 216008 MFC r314708: For now, revert r287232 from upstream llvm trunk (by Daniil Fukalov): [SCEV] limit recursion depth of CompareSCEVComplexity Summary: CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled loop) and runs almost infinite time. Added cache of "equal" SCEV pairs to earlier cutoff of further estimation. Recursion depth limit was also introduced as a parameter. Reviewers: sanjoy Subscribers: mzolotukhin, tstellarAMD, llvm-commits Differential Revision: https://reviews.llvm.org/D26389 This commit is the cause of excessive compile times on skein_block.c (and possibly other files) during kernel builds on amd64. We never saw the problematic behavior described in this upstream commit, so for now it is better to revert it. An upstream bug has been filed here: https://bugs.llvm.org/show_bug.cgi?id=32142 Reported by: mjg MFC r314795: Reapply r287232 from upstream llvm trunk (by Daniil Fukalov): [SCEV] limit recursion depth of CompareSCEVComplexity Summary: CompareSCEVComplexity goes too deep (50+ on a quite a big unrolled loop) and runs almost infinite time. Added cache of "equal" SCEV pairs to earlier cutoff of further estimation. Recursion depth limit was also introduced as a parameter. Reviewers: sanjoy Subscribers: mzolotukhin, tstellarAMD, llvm-commits Differential Revision: https://reviews.llvm.org/D26389 Pull in r296992 from upstream llvm trunk (by Sanjoy Das): [SCEV] Decrease the recursion threshold for CompareValueComplexity Fixes PR32142. r287232 accidentally increased the recursion threshold for CompareValueComplexity from 2 to 32. This change reverses that change by introducing a separate flag for CompareValueComplexity's threshold. The latter revision fixes the excessive compile times for skein_block.c. MFC r314907 | mmel | 2017-03-08 12:40:27 +0100 (Wed, 08 Mar 2017) | 7 lines Unbreak ARMv6 world. The new compiler_rt library imported with clang 4.0.0 have several fatal issues (non-functional __udivsi3 for example) with ARM specific instrict functions. As temporary workaround, until upstream solve these problems, disable all thumb[1][2] related feature. MFC r315016: Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release. We were already very close to the last release candidate, so this is a pretty minor update. Relnotes: yes MFC r316005: Revert r314907, and pull in r298713 from upstream compiler-rt trunk (by Weiming Zhao): builtins: Select correct code fragments when compiling for Thumb1/Thum2/ARM ISA. Summary: Value of __ARM_ARCH_ISA_THUMB isn't based on the actual compilation mode (-mthumb, -marm), it reflect's capability of given CPU. Due to this: - use __tbumb__ and __thumb2__ insteand of __ARM_ARCH_ISA_THUMB - use '.thumb' directive consistently in all affected files - decorate all thumb functions using DEFINE_COMPILERRT_THUMB_FUNCTION() --------- Note: This patch doesn't fix broken Thumb1 variant of __udivsi3 ! Reviewers: weimingz, rengolin, compnerd Subscribers: aemerson, dim Differential Revision: https://reviews.llvm.org/D30938 Discussed with: mmel --- .../llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 386 ++++++++++++++++----- 1 file changed, 294 insertions(+), 92 deletions(-) (limited to 'contrib/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp') diff --git a/contrib/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/contrib/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp index 81963e5..64b888e 100644 --- a/contrib/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/contrib/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -11,43 +11,76 @@ /// //===----------------------------------------------------------------------===// +#include "CoverageReport.h" #include "SourceCoverageViewHTML.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Format.h" #include "llvm/Support/Path.h" using namespace llvm; namespace { +// Return a string with the special characters in \p Str escaped. +std::string escape(StringRef Str, const CoverageViewOptions &Opts) { + std::string Result; + unsigned ColNum = 0; // Record the column number. + for (char C : Str) { + ++ColNum; + if (C == '&') + Result += "&"; + else if (C == '<') + Result += "<"; + else if (C == '>') + Result += ">"; + else if (C == '\"') + Result += """; + else if (C == '\n' || C == '\r') { + Result += C; + ColNum = 0; + } else if (C == '\t') { + // Replace '\t' with TabSize spaces. + unsigned NumSpaces = Opts.TabSize - (--ColNum % Opts.TabSize); + for (unsigned I = 0; I < NumSpaces; ++I) + Result += " "; + ColNum += NumSpaces; + } else + Result += C; + } + return Result; +} + +// Create a \p Name tag around \p Str, and optionally set its \p ClassName. +std::string tag(const std::string &Name, const std::string &Str, + const std::string &ClassName = "") { + std::string Tag = "<" + Name; + if (ClassName != "") + Tag += " class='" + ClassName + "'"; + return Tag + ">" + Str + ""; +} + +// Create an anchor to \p Link with the label \p Str. +std::string a(const std::string &Link, const std::string &Str, + const std::string &TargetName = "") { + std::string Name = TargetName.empty() ? "" : ("name='" + TargetName + "' "); + return "" + Str + ""; +} + const char *BeginHeader = "" "" ""; const char *CSSForCoverage = - ""; +)"; const char *EndHeader = ""; @@ -170,48 +224,40 @@ const char *BeginTable = ""; const char *EndTable = "
"; -void emitPrelude(raw_ostream &OS) { - OS << "" - "" - << BeginHeader << CSSForCoverage << EndHeader << "" - << BeginCenteredDiv; -} +const char *ProjectTitleTag = "h1"; -void emitEpilog(raw_ostream &OS) { - OS << EndCenteredDiv << "" - ""; -} +const char *ReportTitleTag = "h2"; -// Return a string with the special characters in \p Str escaped. -std::string escape(StringRef Str) { - std::string Result; - for (char C : Str) { - if (C == '&') - Result += "&"; - else if (C == '<') - Result += "<"; - else if (C == '>') - Result += ">"; - else if (C == '\"') - Result += """; - else - Result += C; - } - return Result; +const char *CreatedTimeTag = "h4"; + +std::string getPathToStyle(StringRef ViewPath) { + std::string PathToStyle = ""; + std::string PathSep = sys::path::get_separator(); + unsigned NumSeps = ViewPath.count(PathSep); + for (unsigned I = 0, E = NumSeps; I < E; ++I) + PathToStyle += ".." + PathSep; + return PathToStyle + "style.css"; } -// Create a \p Name tag around \p Str, and optionally set its \p ClassName. -std::string tag(const std::string &Name, const std::string &Str, - const std::string &ClassName = "") { - std::string Tag = "<" + Name; - if (ClassName != "") - Tag += " class='" + ClassName + "'"; - return Tag + ">" + Str + ""; +void emitPrelude(raw_ostream &OS, const CoverageViewOptions &Opts, + const std::string &PathToStyle = "") { + OS << "" + "" + << BeginHeader; + + // Link to a stylesheet if one is available. Otherwise, use the default style. + if (PathToStyle.empty()) + OS << ""; + else + OS << ""; + + OS << EndHeader << ""; } -// Create an anchor to \p Link with the label \p Str. -std::string a(const std::string &Link, const std::string &Str) { - return "" + Str + ""; +void emitEpilog(raw_ostream &OS) { + OS << "" + << ""; } } // anonymous namespace @@ -223,7 +269,14 @@ CoveragePrinterHTML::createViewFile(StringRef Path, bool InToplevel) { return OSOrErr; OwnedStream OS = std::move(OSOrErr.get()); - emitPrelude(*OS.get()); + + if (!Opts.hasOutputDirectory()) { + emitPrelude(*OS.get(), Opts); + } else { + std::string ViewPath = getOutputPath(Path, "html", InToplevel); + emitPrelude(*OS.get(), Opts, getPathToStyle(ViewPath)); + } + return std::move(OS); } @@ -231,39 +284,134 @@ void CoveragePrinterHTML::closeViewFile(OwnedStream OS) { emitEpilog(*OS.get()); } -Error CoveragePrinterHTML::createIndexFile(ArrayRef SourceFiles) { +/// Emit column labels for the table in the index. +static void emitColumnLabelsForIndex(raw_ostream &OS) { + SmallVector Columns; + Columns.emplace_back(tag("td", "Filename", "column-entry-left")); + for (const char *Label : {"Function Coverage", "Instantiation Coverage", + "Line Coverage", "Region Coverage"}) + Columns.emplace_back(tag("td", Label, "column-entry")); + OS << tag("tr", join(Columns.begin(), Columns.end(), "")); +} + +/// Render a file coverage summary (\p FCS) in a table row. If \p IsTotals is +/// false, link the summary to \p SF. +void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF, + const FileCoverageSummary &FCS, + bool IsTotals) const { + SmallVector Columns; + + // Format a coverage triple and add the result to the list of columns. + auto AddCoverageTripleToColumn = [&Columns](unsigned Hit, unsigned Total, + float Pctg) { + std::string S; + { + raw_string_ostream RSO{S}; + if (Total) + RSO << format("%*.2f", 7, Pctg) << "% "; + else + RSO << "- "; + RSO << '(' << Hit << '/' << Total << ')'; + } + const char *CellClass = "column-entry-yellow"; + if (Hit == Total) + CellClass = "column-entry-green"; + else if (Pctg < 80.0) + CellClass = "column-entry-red"; + Columns.emplace_back(tag("td", tag("pre", S), CellClass)); + }; + + // Simplify the display file path, and wrap it in a link if requested. + std::string Filename; + if (IsTotals) { + Filename = "TOTALS"; + } else { + SmallString<128> LinkTextStr(sys::path::relative_path(FCS.Name)); + sys::path::remove_dots(LinkTextStr, /*remove_dot_dots=*/true); + sys::path::native(LinkTextStr); + std::string LinkText = escape(LinkTextStr, Opts); + std::string LinkTarget = + escape(getOutputPath(SF, "html", /*InToplevel=*/false), Opts); + Filename = a(LinkTarget, LinkText); + } + + Columns.emplace_back(tag("td", tag("pre", Filename))); + AddCoverageTripleToColumn(FCS.FunctionCoverage.Executed, + FCS.FunctionCoverage.NumFunctions, + FCS.FunctionCoverage.getPercentCovered()); + AddCoverageTripleToColumn(FCS.InstantiationCoverage.Executed, + FCS.InstantiationCoverage.NumFunctions, + FCS.InstantiationCoverage.getPercentCovered()); + AddCoverageTripleToColumn(FCS.LineCoverage.Covered, FCS.LineCoverage.NumLines, + FCS.LineCoverage.getPercentCovered()); + AddCoverageTripleToColumn(FCS.RegionCoverage.Covered, + FCS.RegionCoverage.NumRegions, + FCS.RegionCoverage.getPercentCovered()); + + OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row"); +} + +Error CoveragePrinterHTML::createIndexFile( + ArrayRef SourceFiles, + const coverage::CoverageMapping &Coverage) { + // Emit the default stylesheet. + auto CSSOrErr = createOutputStream("style", "css", /*InToplevel=*/true); + if (Error E = CSSOrErr.takeError()) + return E; + + OwnedStream CSS = std::move(CSSOrErr.get()); + CSS->operator<<(CSSForCoverage); + + // Emit a file index along with some coverage statistics. auto OSOrErr = createOutputStream("index", "html", /*InToplevel=*/true); if (Error E = OSOrErr.takeError()) return E; auto OS = std::move(OSOrErr.get()); raw_ostream &OSRef = *OS.get(); + assert(Opts.hasOutputDirectory() && "No output directory for index file"); + emitPrelude(OSRef, Opts, getPathToStyle("")); + + // Emit some basic information about the coverage report. + if (Opts.hasProjectTitle()) + OSRef << tag(ProjectTitleTag, escape(Opts.ProjectTitle, Opts)); + OSRef << tag(ReportTitleTag, "Coverage Report"); + if (Opts.hasCreatedTime()) + OSRef << tag(CreatedTimeTag, escape(Opts.CreatedTimeStr, Opts)); + + // Emit a link to some documentation. + OSRef << tag("p", "Click " + + a("http://clang.llvm.org/docs/" + "SourceBasedCodeCoverage.html#interpreting-reports", + "here") + + " for information about interpreting this report."); + // Emit a table containing links to reports for each file in the covmapping. - emitPrelude(OSRef); - OSRef << BeginSourceNameDiv << "Index" << EndSourceNameDiv; - OSRef << BeginTable; - for (StringRef SF : SourceFiles) { - std::string LinkText = escape(sys::path::relative_path(SF)); - std::string LinkTarget = - escape(getOutputPath(SF, "html", /*InToplevel=*/false)); - OSRef << tag("tr", tag("td", tag("pre", a(LinkTarget, LinkText), "code"))); - } - OSRef << EndTable; + OSRef << BeginCenteredDiv << BeginTable; + emitColumnLabelsForIndex(OSRef); + FileCoverageSummary Totals("TOTALS"); + auto FileReports = + CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles); + for (unsigned I = 0, E = FileReports.size(); I < E; ++I) + emitFileSummary(OSRef, SourceFiles[I], FileReports[I]); + emitFileSummary(OSRef, "Totals", Totals, /*IsTotals=*/true); + OSRef << EndTable << EndCenteredDiv + << tag("h5", escape(Opts.getLLVMVersionString(), Opts)); emitEpilog(OSRef); return Error::success(); } void SourceCoverageViewHTML::renderViewHeader(raw_ostream &OS) { - OS << BeginTable; + OS << BeginCenteredDiv << BeginTable; } void SourceCoverageViewHTML::renderViewFooter(raw_ostream &OS) { - OS << EndTable; + OS << EndTable << EndCenteredDiv; } -void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS) { - OS << BeginSourceNameDiv << tag("pre", escape(getSourceName())) +void SourceCoverageViewHTML::renderSourceName(raw_ostream &OS, bool WholeFile) { + OS << BeginSourceNameDiv << tag("pre", escape(getSourceName(), getOptions())) << EndSourceNameDiv; } @@ -287,6 +435,7 @@ void SourceCoverageViewHTML::renderLine( raw_ostream &OS, LineRef L, const coverage::CoverageSegment *WrappedSegment, CoverageSegmentArray Segments, unsigned ExpansionCol, unsigned) { StringRef Line = L.Line; + unsigned LineNo = L.LineNo; // Steps for handling text-escaping, highlighting, and tooltip creation: // @@ -299,33 +448,32 @@ void SourceCoverageViewHTML::renderLine( unsigned LCol = 1; auto Snip = [&](unsigned Start, unsigned Len) { - assert(Start + Len <= Line.size() && "Snippet extends past the EOL"); Snippets.push_back(Line.substr(Start, Len)); LCol += Len; }; Snip(LCol - 1, Segments.empty() ? 0 : (Segments.front()->Col - 1)); - for (unsigned I = 1, E = Segments.size(); I < E; ++I) { - assert(LCol == Segments[I - 1]->Col && "Snippet start position is wrong"); + for (unsigned I = 1, E = Segments.size(); I < E; ++I) Snip(LCol - 1, Segments[I]->Col - LCol); - } // |Line| + 1 is needed to avoid underflow when, e.g |Line| = 0 and LCol = 1. Snip(LCol - 1, Line.size() + 1 - LCol); - assert(LCol == Line.size() + 1 && "Final snippet doesn't reach the EOL"); // 2. Escape all of the snippets. for (unsigned I = 0, E = Snippets.size(); I < E; ++I) - Snippets[I] = escape(Snippets[I]); + Snippets[I] = escape(Snippets[I], getOptions()); - // 3. Use \p WrappedSegment to set the highlight for snippets 0 and 1. Use - // segment 1 to set the highlight for snippet 2, segment 2 to set the - // highlight for snippet 3, and so on. + // 3. Use \p WrappedSegment to set the highlight for snippet 0. Use segment + // 1 to set the highlight for snippet 2, segment 2 to set the highlight for + // snippet 3, and so on. Optional Color; - auto Highlight = [&](const std::string &Snippet) { + SmallVector, 2> HighlightedRanges; + auto Highlight = [&](const std::string &Snippet, unsigned LC, unsigned RC) { + if (getOptions().Debug) + HighlightedRanges.emplace_back(LC, RC); return tag("span", Snippet, Color.getValue()); }; @@ -333,14 +481,13 @@ void SourceCoverageViewHTML::renderLine( return S && S->HasCount && S->Count == 0; }; - if (CheckIfUncovered(WrappedSegment) || - CheckIfUncovered(Segments.empty() ? nullptr : Segments.front())) { + if (CheckIfUncovered(WrappedSegment)) { Color = "red"; - Snippets[0] = Highlight(Snippets[0]); - Snippets[1] = Highlight(Snippets[1]); + if (!Snippets[0].empty()) + Snippets[0] = Highlight(Snippets[0], 1, 1 + Snippets[0].size()); } - for (unsigned I = 1, E = Segments.size(); I < E; ++I) { + for (unsigned I = 0, E = Segments.size(); I < E; ++I) { const auto *CurSeg = Segments[I]; if (CurSeg->Col == ExpansionCol) Color = "cyan"; @@ -350,7 +497,22 @@ void SourceCoverageViewHTML::renderLine( Color = None; if (Color.hasValue()) - Snippets[I + 1] = Highlight(Snippets[I + 1]); + Snippets[I + 1] = Highlight(Snippets[I + 1], CurSeg->Col, + CurSeg->Col + Snippets[I + 1].size()); + } + + if (Color.hasValue() && Segments.empty()) + Snippets.back() = Highlight(Snippets.back(), 1, 1 + Snippets.back().size()); + + if (getOptions().Debug) { + for (const auto &Range : HighlightedRanges) { + errs() << "Highlighted line " << LineNo << ", " << Range.first << " -> "; + if (Range.second == 0) + errs() << "?"; + else + errs() << Range.second; + errs() << "\n"; + } } // 4. Snippets[1:N+1] correspond to \p Segments[0:N]: use these to generate @@ -373,7 +535,7 @@ void SourceCoverageViewHTML::renderLine( Snippets[I + 1] = tag("div", Snippets[I + 1] + tag("span", formatCount(CurSeg->Count), - "tooltip-content"), + "tooltip-content"), "tooltip"); } } @@ -402,7 +564,10 @@ void SourceCoverageViewHTML::renderLineCoverageColumn( void SourceCoverageViewHTML::renderLineNumberColumn(raw_ostream &OS, unsigned LineNo) { - OS << tag("td", tag("pre", utostr(uint64_t(LineNo))), "line-number"); + std::string LineNoStr = utostr(uint64_t(LineNo)); + std::string TargetName = "L" + LineNoStr; + OS << tag("td", a("#" + TargetName, tag("pre", LineNoStr), TargetName), + "line-number"); } void SourceCoverageViewHTML::renderRegionMarkers(raw_ostream &, @@ -431,6 +596,43 @@ void SourceCoverageViewHTML::renderInstantiationView(raw_ostream &OS, InstantiationView &ISV, unsigned ViewDepth) { OS << BeginExpansionDiv; - ISV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/true, ViewDepth); + if (!ISV.View) + OS << BeginSourceNameDiv + << tag("pre", + escape("Unexecuted instantiation: " + ISV.FunctionName.str(), + getOptions())) + << EndSourceNameDiv; + else + ISV.View->print(OS, /*WholeFile=*/false, /*ShowSourceName=*/true, + ViewDepth); OS << EndExpansionDiv; } + +void SourceCoverageViewHTML::renderTitle(raw_ostream &OS, StringRef Title) { + if (getOptions().hasProjectTitle()) + OS << tag(ProjectTitleTag, escape(getOptions().ProjectTitle, getOptions())); + OS << tag(ReportTitleTag, escape(Title, getOptions())); + if (getOptions().hasCreatedTime()) + OS << tag(CreatedTimeTag, + escape(getOptions().CreatedTimeStr, getOptions())); +} + +void SourceCoverageViewHTML::renderTableHeader(raw_ostream &OS, + unsigned FirstUncoveredLineNo, + unsigned ViewDepth) { + std::string SourceLabel; + if (FirstUncoveredLineNo == 0) { + SourceLabel = tag("td", tag("pre", "Source")); + } else { + std::string LinkTarget = "#L" + utostr(uint64_t(FirstUncoveredLineNo)); + SourceLabel = + tag("td", tag("pre", "Source (" + + a(LinkTarget, "jump to first uncovered line") + + ")")); + } + + renderLinePrefix(OS, ViewDepth); + OS << tag("td", tag("pre", "Line")) << tag("td", tag("pre", "Count")) + << SourceLabel; + renderLineSuffix(OS, ViewDepth); +} -- cgit v1.1