diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 8dd82d3a9a9..629a485bc1c 100644 --- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -331,15 +331,20 @@ std::string GCOVProfiler::mangleName(DICompileUnit CU, std::string NewStem) { for (int i = 0, e = GCov->getNumOperands(); i != e; ++i) { MDNode *N = GCov->getOperand(i); if (N->getNumOperands() != 2) continue; - MDString *Path = dyn_cast(N->getOperand(0)); + MDString *GCovFile = dyn_cast(N->getOperand(0)); MDNode *CompileUnit = dyn_cast(N->getOperand(1)); - if (!Path || !CompileUnit) continue; - if (CompileUnit == CU) - return (Path->getString() + "/" + - replaceStem(CU.getFilename(), NewStem)).str(); + if (!GCovFile || !CompileUnit) continue; + if (CompileUnit == CU) { + SmallString<128> Filename = GCovFile->getString(); + sys::path::replace_extension(Filename, NewStem); + return Filename.str(); + } } } - return replaceStem(CU.getFilename(), NewStem); + + SmallString<128> Filename = CU.getFilename(); + sys::path::replace_extension(Filename, NewStem); + return sys::path::filename(Filename.str()); } bool GCOVProfiler::runOnModule(Module &M) {