How CSS markup fragment broke the C ++ compiler

    Picture 1

    The static analysis methodology uses different technologies. One of them is the preprocessing of files immediately before their analysis. Preprocessed files are created by a compiler that runs in a special mode of operation. Unfortunately, this mode is not very well tested, as our many years of experience in developing a static code analyzer shows. In this note, I will give an example of a freshly found bug in the C ++ compiler from Microsoft.

    Introduction


    To demonstrate the capabilities of the PVS-Studio static analyzer, our team checks the source code of Open Source projects. This is a significant contribution to the quality of open source software, additional advertising and analyzer testing. Sometimes we find very unusual problems in compilers that are difficult to do on the analyzer side. So, a colleague recently wrote an article “The file with the 'import' directive (compiler internal error 'msc1.cpp') has ceased to be analyzed. What should I do? " To help our users in solving a "foreign" problem.

    What about CSS?


    An equally interesting bug was just found by me when checking out a large project. The Microsoft compiler for C / C ++ version 19.16.27027.1 (Visual Studio v15.9.9) produced this error when analyzing several files:

    fatal error C1021: invalid preprocessor command 'tooltiphint'

    Obviously, this is not a preprocessor directive, but what is it? This is a snippet of CSS code:

    #tooltiphint {
      position: fixed;
      width: 50em;
      margin-left: -25em;
      left: 50%;
      padding: 10px;
      border: 1px solid #b0b0b0;
      border-radius: 2px;
      box-shadow: 1px 1px 7px black;
      background-color: #c0c0c0;
      z-index: 2;
    }

    After viewing the fragment, it became clear that the compiler was mistaken during the preprocessing of the file, but the code was compiled successfully. A snippet of CSS code is part of the string literal of C ++ code. Here is a sample code sufficient to repeat the error:

    std::string test = R"<<<(
    
    
    )<<<";

    The above code fragment does not interfere with successful compilation, but, at the same time, an error occurs in the preprocessing mode (flag / P ).

    This is such a difficult life for developers of static analyzers :). It seems that PVS-Studio is not to blame, but still we should deal with similar problems. However, this is not something new. Some other similar cases can be found in the article " PVS-Studio and the hostile environment ."

    Conclusion


    This problem will be sent to the official bug tracker, but a quick solution to the problem is hardly possible. For example, the problem with the #import directive that we identified several months ago, which I wrote about at the beginning, will be fixed only in the next release of Visual Studio. Because The release of the new Visual Studio 2019 will take place in a week, most likely, this bug will not be fixed by this date. PVS-Studio users are also advised to use the PVS_STUDIO macro .



    If you want to share this article with an English-speaking audience, then please use the link to the translation: Svyatoslav Razmyslov. How the CSS markup fragment broke the C ++ compiler

    Also popular now: