[Coverage] Support overriding compilation directory
authorPetr Hosek <phosek@google.com>
Fri, 9 Apr 2021 18:53:59 +0000 (11:53 -0700)
committerPetr Hosek <phosek@google.com>
Tue, 11 May 2021 22:26:45 +0000 (15:26 -0700)
commit8280ece0c972db24e51aae5074ca5433002f1071
treed0349813ad8a97abc2413e11d1c06636d0ecdf1d
parenta0162a81b1377331c3e0ebb58ac349b2ffd7b598
[Coverage] Support overriding compilation directory

When making compilation relocatable, for example in distributed
compilation scenarios, we want to set compilation dir to a relative
value like `.` but this presents a problem when generating reports
because if the file path is relative as well, for example `..`, you
may end up writing files outside of the output directory.

This change introduces a flag that allows overriding the compilation
directory that's stored inside the profile with a different value that
is absolute.

Differential Revision: https://reviews.llvm.org/D100232
llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
llvm/include/llvm/ProfileData/Coverage/CoverageMappingReader.h
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp
llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
llvm/test/tools/llvm-cov/Inputs/compilation_dir.covmapping [new file with mode: 0644]
llvm/test/tools/llvm-cov/Inputs/compilation_dir.proftext [new file with mode: 0644]
llvm/test/tools/llvm-cov/compilation_dir.c [new file with mode: 0644]
llvm/tools/llvm-cov/CodeCoverage.cpp
llvm/tools/llvm-cov/CoverageViewOptions.h
llvm/unittests/ProfileData/CoverageMappingTest.cpp