summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2019-10-10 18:01:20 +0000
committerReid Kleckner <rnk@google.com>2019-10-10 18:01:20 +0000
commita2a3b137f8656b07a18fc58778552c803b746a91 (patch)
treec5cdf94462eef76b8a3be759001bf50d9b6c4ab2 /lib
parentb97b530ceab5c60f9617a42e1e514098540f2f13 (diff)
downloadclang-a2a3b137f8656b07a18fc58778552c803b746a91.tar.gz
Re-land "Use -fdebug-compilation-dir to form absolute paths in coverage mappings"
This reverts r374324 (git commit 62808631acceaa8b78f8ab9b407eb6b943ff5f77) I changed the test to not rely on finding the sequence "clang, test, CoverageMapping" in the CWD used to run the test. Instead it makes its own internal directory hierarchy of foo/bar/baz and looks for that. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374403 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/CoverageMappingGen.cpp25
-rw-r--r--lib/CodeGen/CoverageMappingGen.h8
2 files changed, 24 insertions, 9 deletions
diff --git a/lib/CodeGen/CoverageMappingGen.cpp b/lib/CodeGen/CoverageMappingGen.cpp
index 0a7a4fe33a..a6f6e38d5f 100644
--- a/lib/CodeGen/CoverageMappingGen.cpp
+++ b/lib/CodeGen/CoverageMappingGen.cpp
@@ -1278,13 +1278,6 @@ 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,
@@ -1317,6 +1310,24 @@ 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) {
diff --git a/lib/CodeGen/CoverageMappingGen.h b/lib/CodeGen/CoverageMappingGen.h
index 3bf51f5904..2bdc00e256 100644
--- a/lib/CodeGen/CoverageMappingGen.h
+++ b/lib/CodeGen/CoverageMappingGen.h
@@ -54,10 +54,14 @@ 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)
- : CGM(CGM), SourceInfo(SourceInfo), FunctionRecordTy(nullptr) {}
+ CoverageMappingModuleGen(CodeGenModule &CGM, CoverageSourceInfo &SourceInfo);
CoverageSourceInfo &getSourceInfo() const {
return SourceInfo;