diff --git a/llvm/docs/CommandGuide/llvm-cov.rst b/llvm/docs/CommandGuide/llvm-cov.rst --- a/llvm/docs/CommandGuide/llvm-cov.rst +++ b/llvm/docs/CommandGuide/llvm-cov.rst @@ -264,6 +264,13 @@ Skip source code files with file paths that match the given regular expression. +.. option:: -ignore-symlinks + + Do not follow symbolic links to detect the same file. Following symbolic links + will generate an accurate report, but this could slow down processing time. + Thus, compare path strings only after normalization instead of following + symbolic links. + .. option:: -format= Use the specified output format. The supported formats are: "text", "html". diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -135,6 +135,7 @@ CoverageViewOptions ViewOpts; CoverageFiltersMatchAll Filters; CoverageFilters IgnoreFilenameFilters; + bool ComparePathStringOnly = false; /// True if InputSourceFiles are provided. bool HadSourceFiles = false; @@ -248,9 +249,22 @@ if (Loc != RemappedFilenames.end()) SourceFile = Loc->second; } - for (const auto &Files : LoadedSourceFiles) - if (sys::fs::equivalent(SourceFile, Files.first)) - return *Files.second; + + SmallString<256> NormalizedPath; + sys::path::native(SourceFile, NormalizedPath); + sys::path::remove_dots(NormalizedPath, true); + SourceFile = NormalizedPath; + + if (ComparePathStringOnly) { + for (const auto &Files : LoadedSourceFiles) + if (SourceFile == Files.first) + return *Files.second; + } else { + for (const auto &Files : LoadedSourceFiles) + if (sys::fs::equivalent(SourceFile, Files.first)) + return *Files.second; + } + auto Buffer = MemoryBuffer::getFile(SourceFile); if (auto EC = Buffer.getError()) { error(EC.message(), SourceFile); @@ -654,6 +668,12 @@ "regular expression"), cl::ZeroOrMore, cl::cat(FilteringCategory)); + cl::opt IgnoreSymlinks( + "ignore-symlinks", cl::Optional, + cl::desc("Do not follow symlinks to check file equivalence. " + "Use only normalized path strings to find the same file."), + cl::init(false)); + cl::opt RegionCoverageLtFilter( "region-coverage-lt", cl::Optional, cl::desc("Show code coverage only for functions with region coverage " @@ -838,6 +858,7 @@ ::exit(0); } + ComparePathStringOnly = IgnoreSymlinks; ViewOpts.ShowBranchSummary = BranchSummary; ViewOpts.ShowRegionSummary = RegionSummary; ViewOpts.ShowInstantiationSummary = InstantiationSummary;