Skip to content

Overview of C and Cpp analysis

duncanp-sonar edited this page Sep 17, 2021 · 12 revisions

Note: this page describes the behaviour of SLVS v4.38+

Supported project types

1. vcxproj projects

SonarLint can analyse .vcxproj projects that use the standard Visual Studio compilation tools. Projects that use third-party tools (such as Unity projects) are not supported.

2. CMake projects - PRE-RELEASE INFORMATION for v4.38

Visual Studio 2017 and later support opening CMake projects in the IDE (see the Microsoft documents for more information).

Starting with v4.38, SonarLint can analyse a subset of CMake project types that meet the following requirements:

  • Visual Studio is configured to use the Ninja generator (the default), and
  • the CMakeLists.txt file contains the following command: set(CMAKE_EXPORT_COMPILE_COMMANDS ON).

See the Analyzing CMake projects in Visual Studio: Getting Started for more information.

Triggering analysis

C/C++ analysis is triggered when a file is opened or saved. Any existing issues for the document will immediately be removed from the Error List. New issues will be added to the Error List incrementally as they are detected.

The status bar will be updated to show the file is being analysed...

Screenshot of status bar showing analysis is in progress

... and again when analysis has finished:

Screenshot of status bar showing analysis has finished

Additional detailed information will be shown in the SonarLint pane of the Output Window.

Note: SonarLint only displays status information in the status bar, as shown in the the above screen shots. Some versions of Visual Studio provide other C++ analysis rules from Microsoft that display progress information in the background tasks pop-up window. These messages do not relate to SonarLint analysis. See here or more information on the Microsoft C++ rules.

C/C++ analysis performance

SonarLint has 450+ rules for C++ and 280+ rules for C. Most run very quickly and will return issues in under a second. However, some of the more advanced rules that involve semantic analysis can take more than ten seconds to run.

Analysis is performed in the background in a separate process. It should not have a noticeable impact on the user experience in Visual Studio. If the analysis is taking too long for a particular file then the analysis process will be terminated. If an analysis is being re-triggered (e.g. via a re-save of the file), the previous analysis will be cancelled and a new analysis will start.

Prior to v4.22, issues were only displayed in the Error List after all rules had finished processing. As of v4.23, issues are displayed in the Error List as soon as they are available. This means that most issues will appear within a few seconds. However, the status bar may still continue to display the analyzing xxx.cpp message for some time until all of the rules have finished processing.

Analysis timeout

By default, an analysis that has not completed within one minute will be stopped and a message logged in the Output Window. We expect such timeouts to be very rare, and probably indicates a problem in one of our analysis rules. If you do encounter timeouts when analysing files, please open an issue in the SonarLint section of the Community Forum and tag it with cfamily.