clang-cl doesn't work with --coverage if /fo is given a directory #87304
Description
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\TestFile.obj" --coverage "TestFile.cpp" outputs Debug/TestFile.obj and DebugTestFile.gcno
"clang-cl.exe" -v /c /Fo"Debug\" --coverage "TestFile.cpp" outputs Debug/TestFile.obj and Debug/.gcno`
Changing this :
llvm-project/clang/lib/Driver/ToolChains/Clang.cpp
Lines 802 to 805 in 49a4ec2
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.
Activity