Index: test/tools/sancov/html-report.test =================================================================== --- test/tools/sancov/html-report.test +++ test/tools/sancov/html-report.test @@ -2,5 +2,5 @@ RUN: sancov -html-report %p/Inputs/test-linux_x86_64 %p/Inputs/test-linux_x86_64.0.sancov | FileCheck %s // It's very difficult to test html report. Do basic smoke check. -CHECK: {{}} +CHECK: {{.*/Inputs/test.cpp}} Index: tools/sancov/sancov.cc =================================================================== --- tools/sancov/sancov.cc +++ tools/sancov/sancov.cc @@ -34,6 +34,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/LineIterator.h" #include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/MD5.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" @@ -488,6 +489,18 @@ return Result; } +static std::string anchorName(std::string Anchor) { + llvm::MD5 Hasher; + llvm::MD5::MD5Result Hash; + Hasher.update(Anchor); + Hasher.final(Hash); + + SmallString<32> HexString; + llvm::MD5::stringifyResult(Hash, HexString); + return HexString.str().str(); +} + + static ErrorOr isCoverageFile(std::string FileName) { ErrorOr> BufOrErr = MemoryBuffer::getFile(FileName); @@ -823,7 +836,7 @@ } size_t CovPct = FC.second == 0 ? 100 : 100 * FC.first / FC.second; - OS << "" + OS << "" << stripPathPrefix(FileName) << "" << "" << CovPct << "%" << "" << FC.first << " (" << FC.second << ")" @@ -852,7 +865,7 @@ std::pair FC = FileFnCoverage[FileName]; if (FC.first == 0) continue; - OS << "\n"; + OS << "\n"; OS << "

" << stripPathPrefix(FileName) << "

\n"; auto NotCoveredFns = NotCoveredFnMap.find(FileName); @@ -862,7 +875,7 @@ for (auto FileFn : NotCoveredFns->second) { OS << ""; OS << ""; + << anchorName(FileName + "::" + FileFn.FunctionName) << "\">"; OS << escapeHtml(FileFn.FunctionName) << ""; OS << "\n"; } @@ -888,7 +901,7 @@ auto It = NotCoveredFnByLoc.find(Loc); if (It != NotCoveredFnByLoc.end()) { for (std::string Fn : It->second) { - OS << ""; }; } @@ -1036,7 +1049,7 @@ // Modules TOC. if (Coverage.size() > 1) { for (const auto &CovData : Coverage) { - OS << "
  • object_file()) + OS << "
  • object_file()) << "\">" << llvm::sys::path::filename(CovData->object_file()) << "
  • \n"; } @@ -1047,7 +1060,7 @@ OS << "

    " << llvm::sys::path::filename(CovData->object_file()) << "

    \n"; } - OS << "object_file()) + OS << "object_file()) << "\">\n"; CovData->printReport(OS); }