Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-cl doesn't work with --coverage if /fo is given a directory #87304

Open
pdagobert opened this issue Apr 2, 2024 · 0 comments · May be fixed by #88201
Open

clang-cl doesn't work with --coverage if /fo is given a directory #87304

pdagobert opened this issue Apr 2, 2024 · 0 comments · May be fixed by #88201
Labels

Comments

@pdagobert
Copy link

pdagobert commented Apr 2, 2024

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 :

} else if (Arg *FinalOutput =
C.getArgs().getLastArg(options::OPT__SLASH_Fo)) {
CoverageFilename = FinalOutput->getValue();
} else if (Arg *FinalOutput = C.getArgs().getLastArg(options::OPT_o)) {

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.

@pdagobert pdagobert linked a pull request Apr 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants