From 0204fd25b0ca9a7bc7db11df238d8ec9f195e67c Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Mon, 21 Mar 2022 18:30:35 -0700 Subject: [PATCH] [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 --- llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp | 3 ++- llvm/test/tools/llvm-cov/Inputs/relative_dir/header.h | 1 + llvm/test/tools/llvm-cov/Inputs/relative_dir/main.c | 5 +++++ .../tools/llvm-cov/Inputs/relative_dir/main.covmapping | Bin 0 -> 157 bytes .../tools/llvm-cov/Inputs/relative_dir/main.proftext | 16 ++++++++++++++++ llvm/test/tools/llvm-cov/coverage-prefix-map.test | 2 +- llvm/test/tools/llvm-cov/relative-dir.test | 10 ++++++++++ llvm/unittests/ProfileData/CoverageMappingTest.cpp | 4 ++-- 8 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 llvm/test/tools/llvm-cov/Inputs/relative_dir/header.h create mode 100644 llvm/test/tools/llvm-cov/Inputs/relative_dir/main.c create mode 100644 llvm/test/tools/llvm-cov/Inputs/relative_dir/main.covmapping create mode 100644 llvm/test/tools/llvm-cov/Inputs/relative_dir/main.proftext create mode 100644 llvm/test/tools/llvm-cov/relative-dir.test diff --git a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp index 0bb1c57..1a18779 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp @@ -175,7 +175,8 @@ Error RawCoverageFilenamesReader::readUncompressed(CovMapVersion Version, else P.assign(CWD); llvm::sys::path::append(P, Filename); - Filenames.push_back(static_cast(P)); + sys::path::remove_dots(P, /*remove_dot_dot=*/true); + Filenames.push_back(static_cast(P.str())); } } } diff --git a/llvm/test/tools/llvm-cov/Inputs/relative_dir/header.h b/llvm/test/tools/llvm-cov/Inputs/relative_dir/header.h new file mode 100644 index 0000000..a39fce09 --- /dev/null +++ b/llvm/test/tools/llvm-cov/Inputs/relative_dir/header.h @@ -0,0 +1 @@ +int f() { return 0; } diff --git a/llvm/test/tools/llvm-cov/Inputs/relative_dir/main.c b/llvm/test/tools/llvm-cov/Inputs/relative_dir/main.c new file mode 100644 index 0000000..26e97a5 --- /dev/null +++ b/llvm/test/tools/llvm-cov/Inputs/relative_dir/main.c @@ -0,0 +1,5 @@ +#include "header.h" + +int main() { + return f(); +} diff --git a/llvm/test/tools/llvm-cov/Inputs/relative_dir/main.covmapping b/llvm/test/tools/llvm-cov/Inputs/relative_dir/main.covmapping new file mode 100644 index 0000000000000000000000000000000000000000..665aa963ebd366591c772941e053e6fbfe5c09e0 GIT binary patch literal 157 zcmd1FDa%dHFUu`SEiOq(EJ@_pYR$%w#+aL!na2PF3Qz_skY<);VBpi!(+8rA)Wnq3 zBE1YA2p6P9FS&oA&)ri0iDx*0Y9*lhL}VwHZ7Gk~!N|zK$jHdaAO;lwb+z}oS<2Mg OSk*BB)iLuhF#!NZSR%jx literal 0 HcmV?d00001 diff --git a/llvm/test/tools/llvm-cov/Inputs/relative_dir/main.proftext b/llvm/test/tools/llvm-cov/Inputs/relative_dir/main.proftext new file mode 100644 index 0000000..ab94aa2f --- /dev/null +++ b/llvm/test/tools/llvm-cov/Inputs/relative_dir/main.proftext @@ -0,0 +1,16 @@ +f +# Func Hash: +24 +# Num Counters: +1 +# Counter Values: +1 + +main +# Func Hash: +24 +# Num Counters: +1 +# Counter Values: +1 + diff --git a/llvm/test/tools/llvm-cov/coverage-prefix-map.test b/llvm/test/tools/llvm-cov/coverage-prefix-map.test index eaebae3..5e8fae4 100644 --- a/llvm/test/tools/llvm-cov/coverage-prefix-map.test +++ b/llvm/test/tools/llvm-cov/coverage-prefix-map.test @@ -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: diff --git a/llvm/test/tools/llvm-cov/relative-dir.test b/llvm/test/tools/llvm-cov/relative-dir.test new file mode 100644 index 0000000..e0e2427 --- /dev/null +++ b/llvm/test/tools/llvm-cov/relative-dir.test @@ -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% diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp index cc4c953..758398d 100644 --- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp +++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp @@ -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); } } } -- 2.7.4