diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -6550,8 +6550,21 @@ llvm::NamedMDNode *GCov = TheModule.getOrInsertNamedMetadata("llvm.gcov"); llvm::LLVMContext &Ctx = TheModule.getContext(); - auto *CoverageDataFile = + llvm::MDString *CoverageDataFile = nullptr; + auto &PrefixMap = getCodeGenOpts().CoveragePrefixMap; + llvm::SmallString<256> File; + if (!PrefixMap.empty()) { + File = getCodeGenOpts().CoverageDataFile; + llvm::sys::path::remove_dots(File, /*remove_dot_dot=*/true); + for (const auto &Entry : PrefixMap) { + if (llvm::sys::path::replace_path_prefix(File, Entry.first, Entry.second)) + break; + } + CoverageDataFile = llvm::MDString::get(Ctx, File.c_str()); + } else { + CoverageDataFile = llvm::MDString::get(Ctx, getCodeGenOpts().CoverageDataFile); + } auto *CoverageNotesFile = llvm::MDString::get(Ctx, getCodeGenOpts().CoverageNotesFile); for (int i = 0, e = CUNode->getNumOperands(); i != e; ++i) {