<div dir="ltr">Hi Adrian,<div><br></div><div>After this change, the .gcno produced by clang store all the paths as absolute (adding the working directory).</div><div>We rely on them being relative internally to produce code coverage.</div><div><br></div><div>I'm afraid I'll have to revert this change (and prior changes that broke compiler-rt) to unbreak our integrate.</div><div>Sorry for the inconvenience.</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 3, 2018 at 11:40 PM Adrian Prantl via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br>
Date: Mon Dec  3 14:37:48 2018<br>
New Revision: 348203<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=348203&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=348203&view=rev</a><br>
Log:<br>
Adapt gcov to changes in CFE.<br>
<br>
The clang frontend no longer emits the current working directory for<br>
DIFiles containing an absolute path in the filename: and will move the<br>
common prefix between current working directory and the file into the<br>
directory: component.<br>
<br>
This fixes the GCOV tests in compiler-rt that were broken by the Clang<br>
change.<br>
<br>
Modified:<br>
    llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp<br>
<br>
Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=348203&r1=348202&r2=348203&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=348203&r1=348202&r2=348203&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Mon Dec  3 14:37:48 2018<br>
@@ -180,6 +180,12 @@ static StringRef getFunctionName(const D<br>
   return SP->getName();<br>
 }<br>
<br>
+template<class DINode> SmallString<128> getFilename(const DINode *N) {<br>
+  SmallString<128> Path;<br>
+  sys::path::append(Path, N->getDirectory(), N->getFilename());<br>
+  return Path;<br>
+}<br>
+<br>
 namespace {<br>
   class GCOVRecord {<br>
    protected:<br>
@@ -256,7 +262,7 @@ namespace {<br>
     }<br>
<br>
    private:<br>
-    StringRef Filename;<br>
+    std::string Filename;<br>
     SmallVector<uint32_t, 32> Lines;<br>
   };<br>
<br>
@@ -377,8 +383,9 @@ namespace {<br>
<br>
     void writeOut() {<br>
       writeBytes(FunctionTag, 4);<br>
+      SmallString<128> Filename = getFilename(SP);<br>
       uint32_t BlockLen = 1 + 1 + 1 + lengthOfGCOVString(getFunctionName(SP)) +<br>
-                          1 + lengthOfGCOVString(SP->getFilename()) + 1;<br>
+                          1 + lengthOfGCOVString(Filename) + 1;<br>
       if (UseCfgChecksum)<br>
         ++BlockLen;<br>
       write(BlockLen);<br>
@@ -387,7 +394,7 @@ namespace {<br>
       if (UseCfgChecksum)<br>
         write(CfgChecksum);<br>
       writeGCOVString(getFunctionName(SP));<br>
-      writeGCOVString(SP->getFilename());<br>
+      writeGCOVString(Filename);<br>
       write(SP->getLine());<br>
<br>
       // Emit count of blocks.<br>
@@ -466,7 +473,7 @@ bool GCOVProfiler::isFunctionInstrumente<br>
   if (FilterRe.empty() && ExcludeRe.empty()) {<br>
     return true;<br>
   }<br>
-  const StringRef Filename = F.getSubprogram()->getFilename();<br>
+  SmallString<128> Filename = getFilename(F.getSubprogram());<br>
   auto It = InstrumentedFiles.find(Filename);<br>
   if (It != InstrumentedFiles.end()) {<br>
     return It->second;<br>
@@ -531,7 +538,7 @@ std::string GCOVProfiler::mangleName(con<br>
     }<br>
   }<br>
<br>
-  SmallString<128> Filename = CU->getFilename();<br>
+  SmallString<128> Filename = getFilename(CU);<br>
   sys::path::replace_extension(Filename, Notes ? "gcno" : "gcda");<br>
   StringRef FName = sys::path::filename(Filename);<br>
   SmallString<128> CurPath;<br>
@@ -688,7 +695,8 @@ void GCOVProfiler::emitProfileNotes() {<br>
       // Add the function line number to the lines of the entry block<br>
       // to have a counter for the function definition.<br>
       uint32_t Line = SP->getLine();<br>
-      Func.getBlock(&EntryBlock).getFile(SP->getFilename()).addLine(Line);<br>
+      auto Filename = getFilename(SP);<br>
+      Func.getBlock(&EntryBlock).getFile(Filename).addLine(Line);<br>
<br>
       for (auto &BB : F) {<br>
         GCOVBlock &Block = Func.getBlock(&BB);<br>
@@ -719,7 +727,7 @@ void GCOVProfiler::emitProfileNotes() {<br>
           if (SP != getDISubprogram(Loc.getScope()))<br>
             continue;<br>
<br>
-          GCOVLines &Lines = Block.getFile(SP->getFilename());<br>
+          GCOVLines &Lines = Block.getFile(Filename);<br>
           Lines.addLine(Loc.getLine());<br>
         }<br>
         Line = 0;<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_7122119258351036958gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>Regards,</div><div>Ilya Biryukov</div></div></div></div></div>