keith created this revision. keith added reviewers: arphaman, vsk, rnk, cfe-commits, kastiglione. Herald added subscribers: llvm-commits, dexonsmith. Herald added projects: clang, LLVM.
This reverts commit 62808631acceaa8b78f8ab9b407eb6b943ff5f77. This was previously reverted because llvm-cov's -path-equivalence usage wasn't working as expected. This does work with `-path-equivalence=,/bar` when used with `-fdebug-compilation-dir .` More discussion: https://lists.llvm.org/pipermail/cfe-dev/2020-June/065668.html Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D81122 Files: clang/lib/CodeGen/CoverageMappingGen.cpp clang/lib/CodeGen/CoverageMappingGen.h clang/test/CoverageMapping/debug-dir.cpp llvm/docs/CommandGuide/llvm-cov.rst
Index: llvm/docs/CommandGuide/llvm-cov.rst =================================================================== --- llvm/docs/CommandGuide/llvm-cov.rst +++ llvm/docs/CommandGuide/llvm-cov.rst @@ -314,7 +314,9 @@ Map the paths in the coverage data to local source file paths. This allows you to generate the coverage data on one machine, and then use llvm-cov on a - different machine where you have the same files on a different path. + different machine where you have the same files on a different path. When + using this option with '-fdebug-compilation-dir .' pass nothing for the 'from' + value. .. program:: llvm-cov report Index: clang/test/CoverageMapping/debug-dir.cpp =================================================================== --- /dev/null +++ clang/test/CoverageMapping/debug-dir.cpp @@ -0,0 +1,16 @@ +// %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 -mllvm -enable-name-compression=false -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 -mllvm -enable-name-compression=false -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() {} Index: clang/lib/CodeGen/CoverageMappingGen.h =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.h +++ clang/lib/CodeGen/CoverageMappingGen.h @@ -60,14 +60,16 @@ llvm::SmallDenseMap<const FileEntry *, unsigned, 8> FileEntries; std::vector<llvm::Constant *> FunctionNames; std::vector<FunctionInfo> FunctionRecords; + SmallString<256> CWD; + + std::string normalizeFilename(StringRef Filename); /// Emit a function record. void emitFunctionMappingRecord(const FunctionInfo &Info, uint64_t FilenamesRef); public: - CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo) - : CGM(CGM), SourceInfo(SourceInfo) {} + CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo); CoverageSourceInfo &getSourceInfo() const { return SourceInfo; Index: clang/lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.cpp +++ clang/lib/CodeGen/CoverageMappingGen.cpp @@ -1279,13 +1279,6 @@ } }; -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 std::string(Path); -} - } // end anonymous namespace static void dump(llvm::raw_ostream &OS, StringRef FunctionName, @@ -1318,6 +1311,24 @@ } } +CoverageMappingModuleGen::CoverageMappingModuleGen( + CodeGenModule &CGM, CoverageSourceInfo &SourceInfo) + : CGM(CGM), SourceInfo(SourceInfo) { + // 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(); +} + static std::string getInstrProfSection(const CodeGenModule &CGM, llvm::InstrProfSectKind SK) { return llvm::getInstrProfSectionName(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits