[PATCH] D123164: [CoverageMapping] Remove dots from paths inside the profile

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 5 16:45:13 PDT 2022


phosek created this revision.
phosek added reviewers: vsk, davidxl.
Herald added a subscriber: hiraditya.
Herald added a project: All.
phosek requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123164

Files:
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/test/tools/llvm-cov/Inputs/relative_dir/header.h
  llvm/test/tools/llvm-cov/Inputs/relative_dir/main.c
  llvm/test/tools/llvm-cov/Inputs/relative_dir/main.covmapping
  llvm/test/tools/llvm-cov/Inputs/relative_dir/main.profdata
  llvm/test/tools/llvm-cov/coverage-prefix-map.test
  llvm/test/tools/llvm-cov/relative-dir.test
  llvm/unittests/ProfileData/CoverageMappingTest.cpp


Index: llvm/unittests/ProfileData/CoverageMappingTest.cpp
===================================================================
--- llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -943,7 +943,7 @@
     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 @@
     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);
     }
   }
 }
Index: llvm/test/tools/llvm-cov/relative-dir.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-cov/relative-dir.test
@@ -0,0 +1,8 @@
+# RUN: llvm-cov report %S/Inputs/relative_dir/main.covmapping \
+# RUN:   -instr-profile %S/Inputs/relative_dir/main.profdata \
+# RUN:   -compilation-dir=%S/Inputs/relative_dir/out/default \
+# RUN:   %S/Inputs/relative_dir/header.h \
+# RUN:   | FileCheck -DDIR=%S/Inputs/relative_dir --check-prefix=REPORT %s
+
+# REPORT: {{^}}[[DIR]]{{/|\\}}header.h{{.*}}
+# REPORT: {{^}}TOTAL{{.*}}100.00%
Index: llvm/test/tools/llvm-cov/coverage-prefix-map.test
===================================================================
--- llvm/test/tools/llvm-cov/coverage-prefix-map.test
+++ 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:
Index: llvm/test/tools/llvm-cov/Inputs/relative_dir/main.c
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-cov/Inputs/relative_dir/main.c
@@ -0,0 +1,5 @@
+#include "header.h"
+
+int main() {
+  return f();
+}
Index: llvm/test/tools/llvm-cov/Inputs/relative_dir/header.h
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-cov/Inputs/relative_dir/header.h
@@ -0,0 +1 @@
+int f() { return 0; }
Index: llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
===================================================================
--- llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
+++ llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
@@ -175,7 +175,8 @@
         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()));
       }
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123164.420658.patch
Type: text/x-patch
Size: 2824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220405/f33dc1f9/attachment.bin>


More information about the llvm-commits mailing list