Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
Unable to analyze a file with 'import' …

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

28 Fév 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.

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.

Popular related articles

S'abonner

Comments (0)

close comment form
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam