To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
USD
EUR
GBP
RUB
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
PVS-Studio for JetBrains CLion: ad astr…

PVS-Studio for JetBrains CLion: ad astra per aspera

Aug 06 2021

The PVS-Studio analyzer already has plugins for such IDEs from JetBrains as Rider, IntelliJ IDEA and Android Studio. Somehow we missed another IDE - CLion. The time has come to make amends! But why would you need PVS-Studio if CLion already has the code analyzer? What problems appeared during development? Keep reading to find answers to these questions.

0849_CLionPluginNew/image1.png

There will be no tech-hardcore in this article. This is more of a story about moments that we stumbled upon during the development process. Chill out and enjoy your reading. ;)

Note. By the way, the JetBrains website provides the results of various surveys for 2021. The figures cover most common language standards, IDEs, tools, etc. I highly recommend to read, it's worthy. CLion is one of the three most used IDEs / editors. What IDEs for C / C++ do you use?

Why would I need PVS-Studio if CLion already has a static analyzer?

Glad you asked! Let me answer you with a small story.

JetBrains maintains a separate Twitter account for CLion where they share various news, tell about new IDE features, etc. One of the tweets was an example of how the global DFA works.

0849_CLionPluginNew/image2.png

The example demonstrates how the static analyzer managed to detect the dereference of buffer null pointer obtained from the foo function. Andrey, our DevRel, decided to modify the example and see how CLion would handle it.

0849_CLionPluginNew/image3.png

Result: the same warning from CLion. PVS-Studio, however, issues two warnings:

  • V522 There might be dereferencing of a potential null pointer 'buffer'.
  • V611 The memory was allocated using 'new' operator but was released using the 'free' function. Consider inspecting operation logics behind the 'buffer' variable.

Here's an answer to the question that we are discussing - PVS-Studio and CLion collaboration will let us detect more errors at the writing code stage. CLion highlights the errors on the fly, but at the same time is limited in the analysis capabilities. PVS-Studio doesn't highlight errors immediately, but it can perform deeper analysis. Note that PVS-Studio has an incremental analysis – the mode that checks only the changed files.

As a result, the CLion analysis and PVS-Studio analysis complete each other. Imagine what would happen if we also added the compiler's warnings... :)

Second birth

Truth be told, we had a plugin prototype for CLion... several years ago. Yes, some time ago we started developing it. But it was not destined to finish it for a number of reasons. The prototype went on the shelf.

Now, since the users became more and more interested, we decided to finish what we've started. More precisely, we had a couple of possible ways. Either we modify the existing prototype, or start all over again.

Spoiler: both were a bumpy ride.

0849_CLionPluginNew/image4.png

After we found the sources in the repository, we decided to check the level of its readiness. What if there's not much to finish? Surprisingly, the code compiled immediately and that cheered us up.

Note. Hello from the C# department! About a year ago we ported the C# analyzer on Linux and macOS. And what's interesting, we managed to run the PVS-Studio on Linux on the very first day of working on the task! Yet the PVS-Studio analyzer for C# for Linux/macOS release was shipped only six months later. Talking about how many nuances get in the way...

Good news: code compiled and the prototype already had some features. Bad news: we still needed to integrate it in IDE. At the same time, the plugin-to-be must have the main features from PVS-Studio plugins for IDEs from JetBrains: Rider, IntelliJ IDEA, Android Studio. It is clear that there will be some specifics. But in general, the user who tries PVS-Studio together with various IDEs, should follow the same scenario for working with the analyzer, interact with the same settings and UI.

As a result, we tried to take the plugin for Rider as a ready-made solution. However, we found out that we couldn't immediately reuse those developments for CLion. Too much specifics.

Here comes a natural question: why don't you start everything from scratch? Just take a ready-made 'template' and add the existing functional from the prototype on it! Well, it's worth a shot.

We have found a template from the JetBrains official website. But after we downloaded it, it turned out that the sample... wasn't compiling.

0849_CLionPluginNew/image5.png

After a short investigation, we found out that it was a sample for older CLion versions. The API has changed in the new ones - hence the problems.

Interestingly, there is an instruction in the JetBrains blog that explains how to fix the sample to make it work. The edits helped launch the sample. However, the approach itself raised a question - why not just make a separate sample?

As a result, after we combined the prototype with the template, we found out that... nothing works. One might want to give up the prototype and write everything from scratch. It seems that to do this we only need a description of API and IDE interaction. But not so fast.

The results of API documentation search looked like this:

0849_CLionPluginNew/image7.png

Jokes aside, we didn't find anything on the JetBrains website. At all. A dubious idea - to search through all the available classes in hope to find the right one. Our developers who made the PVS-Studio plugin for Rider, confirmed our concerns - there is no documentation.

But if you know where to find such docs - please, leave a comment. It will be useful to us and it will be useful to others.

Perhaps, it's time to stop rushing to start everything from 0 - we need to complete what we have. It may be painful, but it's easier than to start the development again. The decision was correct - after some time spent on debugging and editing, it turned out that the prototype, in general, was already doing what was needed. As a result, we quickly managed to teach it to get a list of source code files from the project.

We gradually migrated the code, the plugin acquired functionality. Eventually it started operating as we needed. But this applied only to Windows, since the main development was carried out on this OS. Initially we were writing code for cross-platform compatibility, but after testing under Linux and macOS we had to add some improvements. In some cases, we had to do more than just editing plugin code. We also had to delve into the core of the C++ analyzer. Indeed, it was a multilingual task - knowledge of both Java and C++ came in handy.

There were two major improvements:

  • the C++ analyzer now takes into account environment variables when analyzing via JSON Compilation DB;
  • also, the analyzer learnt to give out the detected problems one by one and not altogether after it analyzed everything. This allowed us to add more interactivity—now you don't need to wait for the end of the analysis to start analyzing errors. We can do it during the analysis.

How to try it?

There wouldn't be an article if we didn't have the result. No intrigue here, alas. :)

The PVS-Studio plugin for CLion is available for use.

0849_CLionPluginNew/image8.png

To try it, you need:

  • request a trial license;
  • install the analyzer itself and the plugin.

You can request a license and download the analyzer here. Follow the link to get an extended trial period for 30 days. ;)

The plugin installation is also simple. You can find the details in the relevant documentations section: how to download, enter the license and what to do next.

Try it, use it, write us if something doesn't work. We also welcome all suggestions on improving the integration.

And we can't help but ask a question: which IDE / editor do you want PVS-Studio to integrate into? Perhaps, Visual Studio Code? ;)

Popular related articles
PVS-Studio for Java

Date: Jan 17 2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 31 2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
The Ultimate Question of Programming, Refactoring, and Everything

Date: Apr 14 2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
PVS-Studio ROI

Date: Jan 30 2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
The Last Line Effect

Date: May 31 2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: Nov 21 2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
Appreciate Static Code Analysis!

Date: Oct 16 2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 22 2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…

Comments (0)

Next comments
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site.
Learn More →
Accept