[PATCH] D95753: [CoverageMapping] Don't absolutize source paths

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 30 17:15:23 PST 2021


phosek created this revision.
phosek added reviewers: vsk, davidxl.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We currently always absolutize paths in coverage mapping. This is
problematic for reproducibility and it poses a problem for distributed
compilation where source location might differ across machines. It also
doesn't match path handling elsewhere in the compiler, for example in
debug info or __FILE__ expansion: we use the path as given to the
compiler, that is if Clang is invoked with a relative source path then
we use the relative path, and if invoked with an absolute path, then we
use the absolute path. This patch changes the coverage mapping behavior
to match that. We still cannonicalize the path by removing dots to avoid
duplicates in the coverage report.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95753

Files:
  clang/lib/CodeGen/CoverageMappingGen.cpp
  clang/test/CoverageMapping/abspath.cpp
  clang/test/Profile/profile-prefix-map.c


Index: clang/test/Profile/profile-prefix-map.c
===================================================================
--- clang/test/Profile/profile-prefix-map.c
+++ clang/test/Profile/profile-prefix-map.c
@@ -5,10 +5,14 @@
 // RUN: echo "void f1() {}" > %t/root/nested/profile-prefix-map.c
 // RUN: cd %t/root
 
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c nested/profile-prefix-map.c -o - | FileCheck --check-prefix=ABSOLUTE %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c %t/root/nested/profile-prefix-map.c -o - | FileCheck --check-prefix=ABSOLUTE %s
 //
 // ABSOLUTE: @__llvm_coverage_mapping = {{.*"\\01.*root.*nested.*profile-prefix-map\.c}}
 
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c nested/profile-prefix-map.c -fprofile-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=PROFILE-PREFIX-MAP %s --implicit-check-not=root
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c ../root/nested/profile-prefix-map.c -o - | FileCheck --check-prefix=RELATIVE %s
 //
+// RELATIVE: @__llvm_coverage_mapping = {{.*"\\01[^/]*}}..{{/|\\+}}root{{/|\\+}}nested{{.*profile-prefix-map\.c}}
+
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c %t/root/nested/profile-prefix-map.c -fprofile-prefix-map=%/t/root=. -o - | FileCheck --check-prefix=PROFILE-PREFIX-MAP %s
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -mllvm -enable-name-compression=false -main-file-name profile-prefix-map.c ../root/nested/profile-prefix-map.c -fprofile-prefix-map=../root=. -o - | FileCheck --check-prefix=PROFILE-PREFIX-MAP %s
 // PROFILE-PREFIX-MAP: @__llvm_coverage_mapping = {{.*"\\01[^/]*}}.{{/|\\+}}nested{{.*profile-prefix-map\.c}}
Index: clang/test/CoverageMapping/abspath.cpp
===================================================================
--- clang/test/CoverageMapping/abspath.cpp
+++ clang/test/CoverageMapping/abspath.cpp
@@ -7,9 +7,14 @@
 // RUN: mkdir -p %t/test && cd %t/test
 // RUN: echo "void f1() {}" > f1.c
 // RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -emit-llvm -main-file-name abspath.cpp ../test/f1.c -o - | FileCheck -check-prefix=RELPATH %s
+// RUN: %clang_cc1 -mllvm -emptyline-comment-coverage=false -fprofile-instrument=clang -fcoverage-mapping -mllvm -enable-name-compression=false -emit-llvm -main-file-name abspath.cpp %t/test/f1.c -o - | FileCheck -check-prefix=ABSPATH %s
 
 // RELPATH: @__llvm_coverage_mapping = {{.*}}"\01
-// RELPATH: {{[/\\].*(/|\\\\)test(/|\\\\)f1}}.c
+// RELPATH: {{..(/|\\\\)test(/|\\\\)f1}}.c
 // RELPATH: "
 
+// ABSPATH: @__llvm_coverage_mapping = {{.*}}"\01
+// ABSPATH: {{[/\\].*(/|\\\\)test(/|\\\\)f1}}.c
+// ABSPATH: "
+
 void f1() {}
Index: clang/lib/CodeGen/CoverageMappingGen.cpp
===================================================================
--- clang/lib/CodeGen/CoverageMappingGen.cpp
+++ clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1593,7 +1593,6 @@
 
 std::string CoverageMappingModuleGen::normalizeFilename(StringRef Filename) {
   llvm::SmallString<256> Path(Filename);
-  llvm::sys::fs::make_absolute(Path);
   llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
   for (const auto &Entry : ProfilePrefixMap) {
     if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95753.320334.patch
Type: text/x-patch
Size: 3812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210131/8b819752/attachment.bin>


More information about the cfe-commits mailing list