Not long ago, a significant event took place: PVS-Studio appeared in Compiler Explorer! Now you can quickly and easily analyze your code for errors right on godbolt.org (Compiler Explorer). This innovation opens up a large number of new possibilities - from satisfying curiosity about the analyzer's capabilities to the ability to quickly share the test result with a friend. How to use these opportunities will be discussed in this article. Beware - Big GIFs!
If you want to get straight to the point and analyze the code here and now, then here's a completely ready-to-use link . I recommend adding it to your bookmarks - it will still come in handy;)
Now let's talk about everything in order. Compiler Explorer is an interactive online service for exploring compilers. Here you can write code right on the site and immediately see what assembly output this or that compiler will generate for it:
In addition, there is a whole set of possibilities on the site, and today we will consider the possibility of analyzing using PVS-Studio. In order to conduct the analysis, you must do the following:
- Go to the website godbolt.org ,
- In the tab with the compiler output, click "Add tool ...",
- Select "PVS-Studio" in the drop-down list.
You can see an example of such a sequence of actions in the animation below:
Done! Now, in the window that appears, all warnings that are issued by the analyzer to your code will be automatically displayed. You can analyze both your own handwritten code and source files downloaded separately. Naturally, the files should be self-contained and not include on files that are not part of the standard library. Otherwise, the file will neither be compiled nor 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 that we support (for example, MSVC or compilers for ARM), if there is a demand for it.
Currently, only General diagnostics of error, warning and note levels are enabled on the site. We deliberately left out the other modes (Optimization, 64-bit, Custom and MISRA) so that only the most important warnings remain in the output. Also, unlike PVS-Studio itself, Compiler Explorer does not yet support C # and Java - we plan to run code analysis 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 each other. If you are not currently interested in the compiler output, you can "hide" it. Like this:
You can either write code directly in the Compiler Explorer window, or download individual files. To do this, click "Save / Load" and select "File system" in the tab that opens. You can also "download" the code you write to your computer by pressing Ctrl + S.
You cannot analyze entire projects on the site - you can only upload files separately.
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). On the gif below you can see the output of the laboratory work taken from our page about the free use of PVS-Studio by students and teachers .
By the way, did you notice that when you click on the links to godbolt, you get a pre-written code in the pre-arranged windows? Yes, you can generate permalinks that completely 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.
This method is very convenient for sharing the results of compilation / analysis of 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 clients 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 "Share" tab there is an item for creating an Embedded link, with which you can embed a window with Compiler Explorer on some other site.
The Compiler Explorer always contains an up-to-date version of PVS-Studio, therefore, after each of our releases, more and more errors can be found on the site. Nevertheless, the use of PVS-Studio on godbolt.org does not give a full picture of its capabilities, because PVS-Studio is not only diagnostics, but also a developed infrastructure:
- Code analysis in C, C ++, C # and Java languages ββfor a much larger number of platforms and compilers;
- Plugins for Visual Studio 2010-2019, JetBrains Rider, IntelliJ IDEA;
- Integration into TeamCity, PlatformIO, Azure DevOps, Travis CI, CircleCI, GitLab CI / CD, Jenkins, SonarQube, etc.
- Compilation monitoring utility for analysis independent of IDE or build system;
- And many many others.
In the end, only after downloading the analyzer you will be able to fully analyze a project consisting of several files. Therefore, the best way to get a correct understanding of PVS-Studio is to download the analyzer and try it on your project.
To stay up to date, follow 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:
- Twitter - @pvsstudio_rus
- Vkontakte - PVS-Studio analyzer
- Facebook - @StaticCodeAnalyzer
- Telegram - PVS-Studio rus
If you want to share this article with an English-speaking audience, please use the translation link: George Gribkov. PVS-Studio is now in Compiler Explorer! .