image1.png

Most recently, a significant event took place: PVS-Studio appeared in Compiler Explorer! Now you can quickly and easily analyze the code for errors right on godbolt.org (Compiler Explorer). This innovation opens up a large number of new possibilities - from quenching curiosity about the analyzer's abilities to being able to quickly share the result of the test with a friend. How to use these features will be discussed in this article. Caution - Big GIFs!

If you want to get down to business immediately and analyze the code here and now, then here’s a link that is completely ready for use. I recommend adding it to your bookmarks - it will come in handy;)

Now let's talk about everything in order. Compiler Explorer is an interactive online service for researching compilers. Here you can write code directly on the site and immediately see which assembler output one or another compiler will generate for it:

image2.gif

In addition, there is a whole range of features on the site, and today we will consider the possibility of analysis using PVS-Studio. In order to conduct an analysis, you must do the following:

  1. Go to godbolt.org ,
  2. In the tab with the compiler output, click "Add tool.",
  3. In the drop-down list, select "PVS-Studio".

You can see an example of such a sequence of actions in the animation below:

image3.gif

Done! Now in the window that appears, all warnings that the analyzer issues to your code will be automatically displayed. You can analyze both your own written code and the source files downloaded individually. Naturally, the files should be self-sufficient and not use include on files that are not part of the standard library. Otherwise, the file cannot be compiled or verified.

At the moment, analysis using PVS-Studio is available on the site for all versions of GCC and Clang for x86 and x64 platforms. We plan to expand the site’s capabilities to other compilers we support (for example, MSVC or compilers for ARM), if this is in demand.

Now only general-diagnostics of error, warning and note levels are included on the site. We deliberately did not turn on the remaining modes (Optimization, 64-bit, Custom, and MISRA) so that only the most important warnings remained in the output. Also, unlike PVS-Studio itself, Compiler Explorer does not yet support C # and Java - we plan to start analyzing the code in these languages ​​as soon as they appear there :)

Compiler Explorer has a very smart window system, so you can move them or, for example, overlap them. If now you are not interested in the output of the compiler, you can "hide" it. Like this:

image4.gif

You can either immediately write code in the Compiler Explorer window, or upload individual files. To do this, click "Save/Load" and select "File system" in the tab that opens. You can also "download" the code you wrote to your computer by pressing Ctrl + S.

image5.gif

The site does not allow you to analyze entire projects - you can only upload files individually.

If you want to see the output of your program, you can open the execution window by clicking "Add new... - > Execution only" in the window for writing code (not in the window with the compiler).In the GIF below you can see the conclusion of the laboratory work taken from our page about free use of PVS-Studio by students and teachers .

image6.gif

By the way, did you notice that when you click on the links to godbolt, you already have pre-entered code in pre-arranged windows? Yes, you can generate permalinks that fully preserve the state of the page at the time of generation! To do this, you need to click on the "Share" button in the upper right corner of the screen.

image7.gif

This method is very convenient for sharing the results of compiling/analyzing your code with friends and colleagues. It is especially convenient that the receiving party literally does not need to do anything: just follow the link, and everything you need will immediately open before your eyes.

We plan to use this opportunity to work with customers in technical support: often using the Compiler Explorer is very convenient for compiling minimally reproducible examples that can be quickly taken and sent by mail.

Also in the drop-down tab "Share" there is an item for creating an Embedded link, with which you can embed a window from the Compiler Explorer on some other site.

Compiler Explorer always has the latest version of PVS-Studio, so after each of our releases on the site you will find more and more errors. Nevertheless, the use of PVS-Studio on godbolt.org does not give a complete picture of its capabilities, because PVS-Studio is not only diagnostics, but also a developed infrastructure:

  • Code analysis in C, C++, C # and Java for a much larger number of platforms and compilers;
  • Plugins for Visual Studio 2010-2019, JetBrains Rider, IntelliJ IDEA;
  • Ability to integrate into TeamCity, PlatformIO, Azure DevOps, Travis CI, CircleCI, GitLab CI/CD, Jenkins, SonarQube, etc.
  • Compilation monitoring utility for analysis regardless of the IDE or assembly system;
  • And much, much more.

In the end, only by downloading the analyzer you can fully analyze the project, which consists of several files. Therefore, the best way to get the right idea about PVS-Studio is to download the analyzer and try it on your project.

To always be in the know, stay tuned for our news. Also read our blog : there we publish not only news and articles about finding bugs in real projects, but also various interesting points related to C, C++, C # and Java.

Our social networks:


ITKarma picture

If you want to share this article with an English-speaking audience, then please use the link to the translation: George Gribkov. PVS-Studio is now in Compiler Explorer! .

Source