Code Coverage on Windows using LLVM clang-cl

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  1. SonarQube Enterprise Edition Version 9.5 (build 56709)
  2. SonarScanner 4.6.2.2472
  3. Visual Studio Build Tools 2019 (version 16.11.18) having LLVM tools version 12
  • what are you trying to achieve

    Publish Code Coverage reports (sonar.cfamily.llvm-cov.reportPath) generated by LLVM on Windows.

  • what have you tried so far to achieve this

  1. The report file is correctly generated according to the Clang documentation.
  2. sonar-scanner is executed with sonar.cfamily.llvm-cov.reportPath pointing to the report file, but it fails with the following errors:
    – INFO: Ignore unknown compiler: C:\BuildTools\VC\Tools\Llvm\x64\bin\clang-cl.exe ... for all the compilation units.
    – At the end the execution fails with the message java.lang.IllegalStateException: The Compilation Database JSON file was found but 0 C/C++/Objective-C files were analyzed.

Questions:

  1. Is the above scenario supported by SonarQube?
  2. If yes, is it possible to publish the Code Coverage reports without also doing the static code analysis at the same time? For more context, this step is automatically done in our CI server, only for the x64-Debug flavour. In parallel we are building the x64-Release flavour, where the static code analysis is performed, but without code coverage metrics. We would like to avoid duplicating performing the static code analysis. I tried specifying sonar.c.file.suffixes=.cdisabled and sonar.cpp.file.suffixes=-, but in this case the code coverage report is ignored altogether.

Thanks!

Hey there.

clang-cl.exe is not supported. Requests for support are tracked in [CPP-2455] - Jira, and we recommend that you check if you can change the build to use the real cl.exe and not clang-cl.exe.

No.

Thanks @Colin,

we recommend that you check if you can change the build to use the real cl.exe and not clang-cl.exe .

We are using the LLVM tools (which come with clang-cl.exe) exclusively to generate the Code Coverage reports on Windows. We have a separated build tree dedicated to this process. The last step in this process would be to publish the report in SonarQube.

clang-cl.exe is not supported.

Does this mean that the scenario “LLVM Code Coverage reports on Windows” is not supported by SonarQube (through sonar.cfamily.llvm-cov.reportPath) ? Please note that the code coverage txt report is well generated by the LLVM tools.

I have the impression you might be wrapping your clang-cl.exe call with the build-wrapper, overwriting your actual compilation results. You don’t need to wrap the call that’s producing code coverage – only your actual build.

I haven’t tried this scenario, but I’d suggest only wrapping your compilation, then run your clang-cl.exe command to generate code coverage, and then run analysis.

Hi @Colin,

I should’ve mentioned this in my initial post: I’m using sonar.cfamily.compile-commands to specify the path to compile_commands.json. The JSON file is found, clang-cl.exe is detected inside, hence the message INFO: Ignore unknown compiler: C:\BuildTools\VC\Tools\Llvm\x64\bin\clang-cl.exe ... is logged for all the compilation units.

Hi @CristiN,

No this is not possible. The analyzer does the analysis and reads the coverage and publishes them in one report. even if clang-cl was supported, you cannot do coverage and analysis each in separate runs. The second analysis will override the results of the first one.

Why not do the static analysis and the coverage with the with x64-Debug flavor?

If for some reason you don’t want to do that and you are using CMake, you can generate the compilation database of x64-Release without building and combine it with the coverage from the x64-Debug.

Thanks,

Hi @Abbas,

Why not do the static analysis and the coverage with the with x64-Debug flavor?

The static code analysis is already performed on the x64-Release. This is the code that gets shipped to the customers, while the Debug flavour is only used internally for development & debugging purposes.
In any case, given the answers received so far - we will have to do both static analysis and code coverage for x64-Debug, despite the fact that it might slow down a bit the PR workflow.

If for some reason you don’t want to do that and you are using CMake, you can generate the compilation database of x64-Release without building and combine it with the coverage from the x64-Debug.

This is exactly what we’re already doing for x64-Release: generating the compilation database without actually building. What do you mean by combine? As far as I know it’s not possible to combine multiple reports into a single report / project (according to SonarCFamily - Compile same code base with several compilers - #2 by mpaladin). Due to the linked issue, w have up to 9 Sonar projects for a single repo (Linux x64, macOS x64/arm64, Windows x86/x64/arm64/, plus 3 more projects for CodeCoverage) :neutral_face:.

I have the feeling the original question on this thread is being lost: is it possible to publish LLVM Code Coverage reports on Windows that were generated using the clang-cl.exe compiler (and also using sonar.cfamily.compile-commands to specify the path to compile_commands.json)?

Thanks.

@CristiN,

Combine it with the coverage in
one run. Yes, it is not possible to combine two runs. Also, it is not possible to combine multiple configs ( Windows x86/x64/arm64/… ) in the same run.

The coverage report is independent of the compiler. there is no restriction on how they are generated.
At the same time, the coverage report is dependent on the analysis. You cannot generate a coverage report if the analysis fails and the analysis is gonna fail if the compilation database only contains clang-cl entries.

So:
clang-cl coverage + clang-cl compilation database → not supported
clang-cl coverage + any supported compiler compilation database → supported.

Let me know if it is still unclear.

Thanks @Abbas,

Everything is clear now, thank you.
Indeed in theory it should be possible to combine the coverage report with the analysis based on the MSVC compiler, but that would complicate our CI workflow. Just to give you an example, the coverage report file contains full paths, which are specific to the build tree. We create separate build trees for clang-cl.exe vs MSVC.

For us it would be ideal for Sonar to support clang-cl.exe on Windows, I guess we’re going to have to wait for [CPP-2455] - Jira to be completed.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.