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

Request our prices
New License
License Renewal
--Select currency--
USD
EUR
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.

>
>
Unable to analyze a file with 'import' …

Unable to analyze a file with 'import' directive (compiler internal error 'msc1.cpp'). What shall I do?

Feb 28 2019

Several times, we got complaints from users that the analysis of some parts of projects wasn't working any more. A common twist was the usage of the '#import' directive in problematic files. This note will briefly describe the reasons of the problem and what has to be done to resume the analysis.

Note. This note is relevant only for Windows when using the 'cl.exe' compiler for preprocessing.

Problem

PVS-Studio uses preprocessed files to search for bugs in code written in C, C++. To get them, the analyzer relies on third-party tools, including the cl.exe compiler. The '/P' flag is used to tell cl.exe to generate preprocessed files.

The problem is that starting from the Visual Studio 15.8 version (and the corresponding Visual C++ version - VC++ 2017 version 15.8 v14.15 toolset), when running cl.exe with the '/P' flag on the files, containing the '#import' directive, an error occurs in the compiler.

Nevertheless, when a compiler is not passed the '/P' flag, a build is performed successfully. From the outside, it might look something like this: a project is successfully built, but the PVS-Studio analyzer does not work. On problem files, the analyzer output will look like this:

c:\program files (x86)\microsoft visual 
studio\2017\community\vc\tools\msvc\14.16.27023\include\comdef.h: 
fatal error C1001: An internal error has occurred in the compiler.
(compiler file 'msc1.cpp', line 1518)
Internal Compiler Error in c:\program files (x86)\microsoft visual 
studio\2017\community\vc\tools\msvc\14.16.27023\bin\hostx64\x64\cl.exe

If you faced such a problem, most likely, your project uses the Platform Toolset V141 and the problem occurred after updating Visual Studio and Visual C++ related packages (and, accordingly the compiler) to a newer version. As a result, the project build is still going successfully, but the analysis - isn't.

To make sure that the problem owns to the compiler, you can try setting the '/P' flag in the configuration options of the related project and perform the build. Setting the flag: Properties|C/C++|Preprocessor|Preprocess to a File -> Yes(/P).

By the way, there is a special topic on the Visual Studio forum: https://developercommunity.visualstudio.com/content/problem/313306/vs2017-158-internal-compiler-error-msc1cpp-line-15-1.html

Solutions

Unfortunately, the described problem still exists and will be fixed, most likely, only in the next Visual Studio release. However, you can continue using PVS-Studio for checking projects, affected by this problem, using a small workaround.

Usage of the 'PVS_STUDIO' macro

When the analyzer runs the compiler in the preprocessing mode, an additional macro is specified - 'PVS_STUDIO'. By using this macro, you can wrap the problematic lines by the #ifdef directive - this will enable the preprocessor to ignore them, without affecting code compilation. At least, you should wrap the '#import' directive:

#if !defined(PVS_STUDIO)
 #import
 ...
#endif

Note, that in this case the part of code, wrapped in the directive, won't get in the resulting preprocessed files. In most cases, this edit won't affect the analysis results.

Usage of the working compiler version

Note. This problem was solved in the compiler version as part of Visual Studio (2017) 15.9.14.

You can opt to use an earlier compiler version (or a new fixed one), in which there is no problem, described above. Let me note, that it appeared starting from the VC++ 2017 Version 15.8 v14.15 toolset.

Note, that Visual Studio 2017 allows installing several Platform Toolset V141 instances on this system, which will get you out of the need to roll back the Platform Toolset version in the project.

0613_ImportCompilerInternalError/image1.png

You can specify the desired compiler versions in the files <VsInstanceDir>\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.[txt|props], where <VsInstanceDir> - configuration directory of a specific Visual Studio release.

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