Issue 87304
Summary clang-cl doesn't work with --coverage if /fo is given a directory
Labels new issue
Assignees
Reporter pdagobert
    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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to