Intel® C++ Compiler XE 13.1 User and Reference Guides

Using Static Analysis

Using Static Analysis from the Microsoft Visual Studio* IDE

To build your application for static analysis in Microsoft Visual Studio, use the Build for Intel Static Analysis menu option. This creates a new build configuration for static analysis and sets the required properties in the Visual Studio IDE.

There are several forms of the Build for Intel Static Analysis menu option, including:

These forms appear in all menus that can build projects or solutions, including the Build menu and the popup menu that appears when you right click on selected project(s) or on the solution.

The first time you use this menu option, a dialog box appears to guide you through the setup process.

Using Static Analysis for an Intel C++ Solution

To perform static analysis on Intel C++ solutions and projects:

  1. Choose Build for Intel Static Analysis.
  2. In the Create configuration dialog box, choose the following:
    • Copy configuration settings from: Specify the configuration from which settings should be copied
    • Level of Static Analysis: Select the desired level of analysis
    • Additional Options: Select Analyze Include Files if you would like to analyze system include files
  3. Leave the Build for Static Analysis after creating configuration checkbox checked. A new configuration called Intel_SSA is created and the project(s) selected for building with static analysis are built. (If you uncheck this checkbox, you will set up for static analysis but not run it at this time).

Analysis results will open automatically in the Intel® Inspector XE user interface.

Using Static Analysis for a Visual C++ Solution or a Mixed Solution

To perform static analysis on Visual C++ only solutions and projects or on a mixed solution containing both Intel C++ and Visual C++ projects, do the following::

  1. Choose Build for Intel Static Analysis.
  2. For Visual Studio 2008: Check and uncheck projects in the Prepare Projects dialog box that appears. This dialog box shows all Visual C++ projects in the solution. Initially, all Visual C++ projects are selected for static analysis. Uncheck any projects that do not require it. Click Next.

    Note

    Existing configurations will not be modified. The Solution Explorer will show a different icon to indicate that a project configuration is built by the Intel compiler.

  3. In the Create configuration dialog box, choose the following:
    • Copy configuration settings from: Specify the configuration from which settings should be copied
    • Level of Static Analysis: Select the desired level of analysis
    • Additional Options: Select Analyze Include Files if you would like to analyze system include files
  4. Leave the Build for Static Analysis after creating configuration checkbox checked. A new configuration called Intel_SSA is created and the project(s) selected for building with static analysis are built. (If you do not click this checkbox, you will set up for static analysis but not run it at this time.)

Analysis results will open automatically in the Intel® Inspector XE user interface.

Note

Preparing a Visual C++ project for use with static analysis does not cause the existing configurations to build with the Intel compiler. However, it does modify the solution (.sln) file and adds an Intel project (.icproj) file for each prepared project. After these changes, the solution will no longer build on systems where the Intel compiler is not installed. In a team environment where some team members will not install the Intel compiler, it is best to treat these modifications as temporary and discard them after running static analysis. You can always use the menu item to perform the preparation step again as needed.

There are several Microsoft Visual Studio* IDE property pages related to static analysis. You can change the options for static analysis by modifying the properties for the Intel_SSA configuration. To do this, use the following property pages:

Using Static Analysis from the Eclipse* IDE

In the Eclipse* IDE:

  1. Open the property pages for the project and select C/C++ Build .

  2. Click the Manage… button.

  3. In the Manage dialog box, click the New… button to open the Create configuration dialog box.

  4. Supply a name for the new configuration in the Name box; for example, Intel_SSA.

  5. Supply a Description for the configuration if you want (optional).

  6. Choose Copy settings from an existing configuration and click the appropriate radio button to select the Debug configuration from the corresponding drop down menu.

  7. Click OK to close the Create configuration dialog box.

  8. Click OK to close the Manage dialog box (with your new configuration name selected).

  9. Navigate to the Intel compiler's Compilation Diagnostics properties.

  10. Use the Level of Static Analysis and Analyze Include Files properties to enable static analysis.

Using Static Analysis from the Command Line

If you are building from the command line, you need to create a new build configuration or target distinct from your existing build configuration or target. Once you do this, you can add the command line options to enable static analysis. You must supply the options that request static analysis on each compilation and link step. The following table summarizes the static analysis options. See the Compiler Options reference for full descriptions of each option.

Option (Windows* and Linux* OS syntax)

Result

/Qdiag-enable:sc{[1|2|3]}

-diag-enable sc{[1|2|3]}

Enables static analysis. The number specifies the severity level of diagnostics reported (1=only critical errors, 2=all errors and warnings, and 3=all diagnostics regardless of severity level).

/Qdiag-enable:sc-{full|concise|precise}

-diag-enable sc-{full|concise|precise}

Enables static analysis and determines the analysis mode.

/Qdiag-disable:sc

-diag-disable sc

Disables static analysis

/Qdiag-enable:sc-include

-diag-enable sc-include

Analyzes system include files as well as source files. By default, apparent errors in system include files are not reported.

System include files are those include files found using the INCLUDE environment variable.

/Qdiag-enable:sc-single-file

-diag-enable sc-single-file

Processes each file individually, skipping the usual whole-program analysis. This reduces memory requirements and analysis time on large programs, but may detect fewer real errors.

/Qdiag-sc-dir:dir

-diag-sc-dir dir

Directs diagnostic results to the given directory. If this option is not specified, or if the option is specified without indicating a directory, results are directed to the current working directory. Each run creates results in a new subdirectory whose name has the form "r@@@sc", where "@@@" is replaced the next available sequence number (001, 002, ...).

This option requires that you also specify the compiler option to enable static analysis.

/Qdiag-enable:sc-enums

-diag-enable sc-enums

Instructs static analysis to treat enumeration variables as known values equal to any one of the associated enumeration literals. By default, static analysis treats unknown enumeration variables as unknown integer values. Setting this option may find additional errors, but tends to create more false positives.

Note

Windows* OS: Even if your project must build on the command line, it is still possible to integrate your project into Visual Studio. To do this, create a Visual Studio "makefile project," in which case, Visual Studio will build the project by invoking a command line of your choosing. If you plan to use a makefile project, you should add the /Qdiag-sc-dir:dir or -diag-sc-dir dir option on the link step to direct the output to the "My Inspector XE Results-<product name>" folder in the project root directory. This allows Intel® Inspector XE to find your results and display them in the Visual Studio Solution Explorer. If you do not want to use Visual Studio at all, you should use the stand-alone form of the Intel® Inspector XE GUI. If you do this, you can place your results wherever you like.

To enable OpenMP*, specify the /Qopenmp (Windows* OS) or -openmp (Linux* OS) option. You must do this if your program uses OpenMP.

Considerations When Using Static Analysis


Submit feedback on this help topic