Revert "Use -fdebug-compilation-dir to form absolute paths in coverage mappings"

This reverts commit 9d4806a387.

There seem to be bugs in llvm-cov --path-equivalence that are causing
Chromium problems. Revert this until they are understood or fixed.
This commit is contained in:
Reid Kleckner 2019-10-28 14:40:17 -07:00
parent de2c7cab71
commit 7cd595df96
3 changed files with 9 additions and 40 deletions

View File

@ -1278,6 +1278,13 @@ std::string getCoverageSection(const CodeGenModule &CGM) {
CGM.getContext().getTargetInfo().getTriple().getObjectFormat());
}
std::string normalizeFilename(StringRef Filename) {
llvm::SmallString<256> Path(Filename);
llvm::sys::fs::make_absolute(Path);
llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
return Path.str().str();
}
} // end anonymous namespace
static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
@ -1310,24 +1317,6 @@ static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
}
}
CoverageMappingModuleGen::CoverageMappingModuleGen(
CodeGenModule &CGM, CoverageSourceInfo &SourceInfo)
: CGM(CGM), SourceInfo(SourceInfo), FunctionRecordTy(nullptr) {
// Honor -fdebug-compilation-dir in paths in coverage data. Otherwise, use the
// regular working directory when normalizing paths.
if (!CGM.getCodeGenOpts().DebugCompilationDir.empty())
CWD = CGM.getCodeGenOpts().DebugCompilationDir;
else
llvm::sys::fs::current_path(CWD);
}
std::string CoverageMappingModuleGen::normalizeFilename(StringRef Filename) {
llvm::SmallString<256> Path(Filename);
llvm::sys::fs::make_absolute(CWD, Path);
llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
return Path.str().str();
}
void CoverageMappingModuleGen::addFunctionMappingRecord(
llvm::GlobalVariable *NamePtr, StringRef NameValue, uint64_t FuncHash,
const std::string &CoverageMapping, bool IsUsed) {

View File

@ -54,14 +54,10 @@ class CoverageMappingModuleGen {
std::vector<llvm::Constant *> FunctionNames;
llvm::StructType *FunctionRecordTy;
std::vector<std::string> CoverageMappings;
SmallString<256> CWD;
/// Make the filename absolute, remove dots, and normalize slashes to local
/// path style.
std::string normalizeFilename(StringRef Filename);
public:
CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo);
CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo)
: CGM(CGM), SourceInfo(SourceInfo), FunctionRecordTy(nullptr) {}
CoverageSourceInfo &getSourceInfo() const {
return SourceInfo;

View File

@ -1,16 +0,0 @@
// %s expands to an absolute path, so to test relative paths we need to create a
// clean directory, put the source there, and cd into it.
// RUN: rm -rf %t
// RUN: mkdir -p %t/foo/bar/baz
// RUN: cp %s %t/foo/bar/baz/debug-dir.cpp
// RUN: cd %t/foo/bar
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -main-file-name debug-dir.cpp baz/debug-dir.cpp -o - | FileCheck -check-prefix=ABSOLUTE %s
//
// ABSOLUTE: @__llvm_coverage_mapping = {{.*"\\01.*foo.*bar.*baz.*debug-dir\.cpp}}
// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -emit-llvm -main-file-name debug-dir.cpp baz/debug-dir.cpp -fdebug-compilation-dir . -o - | FileCheck -check-prefix=RELATIVE %s
//
// RELATIVE: @__llvm_coverage_mapping = {{.*"\\01[^/]*baz.*debug-dir\.cpp}}
void f1() {}