Skip to content

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

Open
@pdagobert

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 :

} 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    clang-cl`clang-cl` driver. Don't use for other compiler parts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions