<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - clang-cl with coverage saves gcno files in root, rather than next to obj file"
   href="https://bugs.llvm.org/show_bug.cgi?id=44208">44208</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-cl with coverage saves gcno files in root, rather than next to obj file
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>9.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Driver
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jeffrey.vandeglind@nobelbiocare.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>While trying to generate code coverage reports for our project, I had an issue
where multiple files with the same name caused issues regarding the writing of
gcda files. Searching online, everything pointed towards gcno files having to
be stored next to the obj files, but for me they were always in the root
folder.

After self-compiling the release_90 branch and inserting some debug prints I
noticed that my generated ninja files didn't contain a -o option. After adding
it, I noticed -o is interpreted as /o, and thus the line that checks for OPT_o
fails, since it is OPT__SLASH_o. It then simply falls back to taking PWD and
source file and generate a path in root.

I then noticed that the flag that clang-cl should actually be looking for is
OPT__SLASH_Fo
(<a href="https://docs.microsoft.com/en-us/cpp/build/reference/fo-object-file-name?view=vs-2019">https://docs.microsoft.com/en-us/cpp/build/reference/fo-object-file-name?view=vs-2019</a>),
so I updated to code (Clang.cpp - addPGOAndCoverageFlags() ~ line 888) to look
like this:

    CmdArgs.push_back("-coverage-notes-file");
    SmallString<128> OutputFilename;
    Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o);
    if (!FinalOutput)
        FinalOutput = C.getArgs().getLastArg(options::OPT__SLASH_Fo);
    if (FinalOutput)
        OutputFilename = FinalOutput->getValue();

This fixes the position of the gcno files. However, I do not know if I am
overseeing some other issues that might pop up due to this change.

My setup is:
Self compiled LLVM + Clang release_90
Microsoft Visual Studio 2019 x64 environment
CMake 3.15 + Ninja 1.9.0</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>