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;