<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/87304>87304</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-cl doesn't work with --coverage if /fo is given a directory
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
pdagobert
</td>
</tr>
</table>
<pre>
I want to add code coverage to a project using CMake and clang-cl. The first issue I'm hitting is that each clang-cl calls issued by CMake will overwrite the same file : "OutputFolder/.gcno", rather than creating one file per .obj file.
This happens because CMake uses /fo with a directory rather than a file, (which is supported according to clang-cl's usage), but when generating the .gcno file, clang-cl will always interprets /fo as a file.
Example :
`"clang-cl.exe" -v /c --coverage "TestFile.cpp"` outputs TestFile.obj and TestFile.gcno
`"clang-cl.exe" -v /c /Fo"Debug\" --coverage "TestFile.cpp"` outputs Debug/TestFile.obj and Debug/.gcno`
Changing this :
https://github.com/llvm/llvm-project/blob/49a4ec20a8be5888cbf225bab340dbaf204902c7/clang/lib/Driver/ToolChains/Clang.cpp#L802-L805
To something like this should work :
```
} else if (Arg *FinalOutput =
C.getArgs().getLastArg(options::OPT__SLASH_Fo)) {
CoverageFilename = FinalOutput->getValue();
if (llvm::sys::path::is_separator(FinalOutput->getValue().back())) {
CoverageFilename += llvm::sys::path::filename(Output.getBaseInput());
}
} else if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o)) {
```
If this is the right way, I can provide a patch.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVV1v4joQ_TXmZQRyJwTCAw98bHQr9WqvtNV9rSbOEHtr4sh2YPn3V04opbu6qy1CATv2nDPnjMcUgmla5rXItyLfT6iP2vl1V1PjKvZxUrn6sn6EM7URogOqa1CuZlDuxJ4aHiah8-47qwh9MG0Du7_plYHaGpSltpkqO4NnzXAwPkQwIfQMjwKXR9AmxrTDBIiaIjApfds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