Source Checker Overview

The Intel® Fortran Compiler Professional product provides the following source code analysis features:

Source Checker

The source checker is a compiler feature that provides advanced diagnostics based on detailed analysis of source code. It performs static global analysis to find errors in software that go undetected by the compiler itself. general source code analysis tool that provides an additional diagnostic capability to help you debug your programs. You can use source code analysis options to detect potential errors in your compiled code including:

The source checker can be used to analyze and find issues with source files; these source files need not form a whole program (for instance, you can check a library source). In such cases, due to the lack of full information on usage and modification of global objects, calls to routines, and so forth, analysis will be less exact.  

Your code must successfully compile, with no errors, for source code analysis options to take effect.

The intended output from the source checker are useful diagnostics; no executable is generated. Object files and library files generated during source checker analysis cannot be used to generate an executable or a dynamic or static library.

Source checker analysis performs a general overview check of a program for all possible values simultaneously. This is in contrast to run-time checking tools that execute a program with a fixed set of values for input variables; such checking tools cannot easily check all edge effects. By not using a fixed set of input values, the source checker analysis can check for all possible corner cases.

Limitations of Source Checker Analysis

Since the source checker does not perform full interpretation of analyzed programs, it can generate so called false-positive messages. This is a fundamental difference between the compiler and source checker generated errors; in the case of the source checker, you decide whether the generated error is legitimate and needs to be fixed.

Example 1: Incorrect message about division by 0

In this example, possible values for parameter x are {6,3}, for parameter y are {3,0}. If x and y both have the value 3, the expression x-y is equal to 0. The source checker cannot identify that the value 3 for x and y cannot coexist.

1 #include <stdio.h>

2

3 double foo(int x, int y) {

4 return 1 / (x - y);

5 }

6

7 int main() {

8 printf("%f\n", foo(6, 3));

9 printf("%f\n", foo(3, 0));

10 return 0;

11 }

The source checker issues the following message:

f1.c(4): error #12062: possible division by 0

Example 2: Incorrect message about uninitialization

This example illustrates how a false positive can appear from conditional statements.

1 #include <stdio.h>

2

3 int main(int n) {

4 int j;

5 if (n != 0) {

6 j = n;

7 }

8 if (n != 0) {

9 printf("%d\n", j);

10 }

11 return 0;

12 }

The source checker issues the following message:

f1.c(9): error #12144: "j" is possibly uninitialized

Parallel Lint

Writing and debugging parallel programs requires specific knowledge and tools. Parallel lint can help in both the development of parallel applications and the parallelizing of existing serial applications. Based on source checker algorithms, parallel lint is a source code analysis capability that performs parallelization analysis of OpenMP* programs. The OpenMP 3.0 standard is supported. OpenMP provides a variety of ways for expressing parallelization. Parallel lint can diagnose problems with OpenMP directives and clauses, including:

In certain cases, an OpenMP program can meet all requirements of the specification but still have serious semantic issues. Parallel lint can help diagnose:

Parallel lint also performs interprocedural analysis and can find issues with parallel directives located in different procedures or files.

Using the Source Code Analysis Options

Source code analysis options include the following:

Option

Result

-diag-enable sc{[1|2|3]} (Linux* OS and Mac OS* X) /Qdiag-enable:sc{[1|2|3]} (Windows* OS)

Enables source checker analysis. The number specifies the several level of the diagnostics (1=all critical errors, 2=all errors, and 3=all errors and warnings)

-diag-disable sc

/Qdiag-disable:sc

Disables source checker analysis

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

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

Enables parallel lint analysis. The number specifies the several level of the diagnostics (1=all critical errors, 2=all errors, and 3=all errors and warnings)

-diag-disable sc-parallel

/Qdiag-disable:sc-parallel

Disables parallel lint analysis

-diag-enable sc-include

/Qdiag-enable:sc-include

Analyzes include files as well as source files.

-diag-disable warn

/Qdiag-disable:warn

Suppresses all warnings, cautions and comments (issues errors only), including those specific to source code analysis

-diag-disable num-list

/Qdiag-disable:num-list

Suppresses messages by number list, where num-list is either a single message or a list of message numbers separated by commas and enclosed in parentheses

-diag-file [file]

/Qdiag-file[:file]

Directs diagnostic results to file with .diag as the default extension. You need to enable source code analysis diagnostics before you can send them to a file. If a file name is not specified, the diagnostics are sent to name-of-the-first-source-file.diag.

-diag-file-append[=file]

/Qdiag-file-append[:file]

Appends diagnostic results to file with .diag as the default extension. You need to enable source code analysis diagnostics before you can send the results to a file. If you do not specify a path, the current working directory will be searched. If the named file is not found, a new file with that name will be created. If a file name is not specified, the diagnostics are sent to name-of-the-first-source-file.diag.

The following notes apply:

Using Source Code Analysis Options with Other Compiler Options

If the -c (Linux OS and Mac OS X) or /c (Windows OS) compiler option is used on the command line along with a command line option to enable source code analysis, an object file is created; source code analysis diagnostics are not produced. This object file may be used in a further invocation of source code analysis. To receive complete source code diagnostics, specify source code analysis options for both compilation and linking phases. This feature is useful when a program consists of files written in different languages (C/C++ and Fortran).

icc -c -diag-enable sc2 file1.c

ifort -c -diag-enable sc2 file2.f90

icc -diag-enable sc2 file1.obj file2.obj

To analyze OpenMP directives, add the -openmp (Linux OS and Mac OS X) or /Qopenmp (Windows OS) option to the command line.

Using Source Code Analysis within the IDE

When source code analysis support is enabled within the IDE, the customary final build target (e.g. an executable image) is not created. Therefore, you should create a separate "Source Code Analysis" configuration.

In the Eclipse* IDE, do the following:


  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, Source Code Analysis.

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

  6. You can choose to Copy settings from a Default configuration or an Existing configuration by clicking the appropriate radio button and then selecting a 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).

The property pages will now display the settings for your new configuration; this becomes the active build configuration. Navigate to the Intel compiler's Compilation Diagnostics properties. Use the Level of Source Code Parallelization Analysis, Level of Source Code Analysis, and Analyze Include Files properties to control source code analysis.

 

Source Checker Capabilities

Source checker analysis capabilities include the following: