[CoverageMapping] Remove dots from paths inside the profile

We already remove dots from collected paths and path mappings. This
makes it difficult to match paths inside the profile which contain
dots. For example, we would never match /path/to/../file.c because
the collected path is always be normalized to /path/file.c. This
change enables dot removal for paths inside the profile to address
the issue.

Differential Revision: https://reviews.llvm.org/D123164
This commit is contained in:
Petr Hosek 2022-03-21 18:30:35 -07:00
parent 779d2470a4
commit 0204fd25b0
8 changed files with 37 additions and 4 deletions

View File

@ -175,7 +175,8 @@ Error RawCoverageFilenamesReader::readUncompressed(CovMapVersion Version,
else
P.assign(CWD);
llvm::sys::path::append(P, Filename);
Filenames.push_back(static_cast<std::string>(P));
sys::path::remove_dots(P, /*remove_dot_dot=*/true);
Filenames.push_back(static_cast<std::string>(P.str()));
}
}
}

View File

@ -0,0 +1 @@
int f() { return 0; }

View File

@ -0,0 +1,5 @@
#include "header.h"
int main() {
return f();
}

View File

@ -0,0 +1,16 @@
f
# Func Hash:
24
# Num Counters:
1
# Counter Values:
1
main
# Func Hash:
24
# Num Counters:
1
# Counter Values:
1

View File

@ -13,7 +13,7 @@
# REPORT: {{^}}bar.h{{.*}}
# REPORT: {{^}}TOTAL{{.*}}100.00%
# LCOV: SF:.{{/|\\+}}bar.h
# LCOV: SF:bar.h
# LCOV-NOT: SF
Instructions for regenerating the test:

View File

@ -0,0 +1,10 @@
# RUN: llvm-profdata merge %S/Inputs/relative_dir/main.proftext \
# RUN: -o %t.profdata
# RUN: llvm-cov report %S/Inputs/relative_dir/main.covmapping \
# RUN: -instr-profile %t.profdata \
# RUN: -compilation-dir=%S/Inputs/relative_dir/out/default \
# RUN: %S/Inputs/relative_dir/header.h \
# RUN: | FileCheck -DDIR=%S %s
# CHECK: {{^}}[[DIR]]{{/|\\}}Inputs{{/|\\}}relative_dir{{/|\\}}header.h{{.*}}
# CHECK: {{^}}TOTAL{{.*}}100.00%

View File

@ -943,7 +943,7 @@ TEST(CoverageMappingTest, filename_roundtrip) {
for (unsigned I = 1; I < Paths.size(); ++I) {
SmallString<256> P(Paths[0]);
llvm::sys::path::append(P, Paths[I]);
ASSERT_TRUE(ReadFilenames[I] == P);
ASSERT_EQ(ReadFilenames[I], P);
}
}
}
@ -969,7 +969,7 @@ TEST(CoverageMappingTest, filename_compilation_dir) {
for (unsigned I = 1; I < Paths.size(); ++I) {
SmallString<256> P(CompilationDir);
llvm::sys::path::append(P, Paths[I]);
ASSERT_TRUE(ReadFilenames[I] == P);
ASSERT_EQ(ReadFilenames[I], P);
}
}
}