Main Content

-classification

Control precisely which files to include in Polyspace Bug Finder analysis and how to analyze them

Since R2023a

Syntax

-classification file

Description

-classification file specifies which files to include in a Polyspace® Bug Finder™ analysis and how to analyze them. Here, file is an XML file that enumerates file sets with specific behaviors.

For instance, you can:

  • Skip the definitions of function bodies in third-party libraries.

  • Force analysis of all functions in files that you own.

If you run a verification:

  • At the command line, specify the absolute path to the XML files or path relative to the folder from which you run the command.

  • In the user interface (desktop products only), in the Other field, specify the option along with an absolute path to the XML or the path relative to the location of your Polyspace project. See Other.

A report generated from the analysis results only show the use of this option and not the details of which behaviors were associated with code elements.

A sample template file classification-template.xml shows the XML syntax. The file is in polyspaceroot\polyspace\verifier\cxx\ where polyspaceroot is the Polyspace installation folder.

Examples

Excluding Generated Files

Suppose your source code consists of the following files. Both .c files contain a comparison that incorrectly uses an = operator instead of an == operator.

  • src\utils.c:

    #include "header.h"
    
    int getEvenElement(int *arr, int size, int idx) {
        int isIndexEven = isEven(idx);
        if(isIndexEven = 0 && idx < size) // Invalid use of = operator
            return arr[idx];
        else
            return -1;
    }
  • src\utils_generated.c:

    #include "header.h"
    
    int isEven(int arg) {
        int rem = arg%2;
        if(rem = 0) { // Invalid use of = operator
            return 1;
        }
        else {
            return 0;
        }
    }
  • inc\header.h:

    int isEven(int);

Run the default Bug Finder analysis:

polyspace-bug-finder -sources src\utils.c,src\utils_generated.c -I inc\
Or:
polyspace-bug-finder-server -sources src\utils.c,src\utils_generated.c -I inc\
You see an Invalid use of = operator defect in both .c files.

Suppose your generated files follow a naming convention and end with _generated. To exclude these files from analysis:

  1. Write a classification file that defines a set of files to exclude from analysis.

    <?xml version="1.0" encoding="UTF-8"?>
    
    <specification>  
        <classification product="bug-finder">
           <fileset name="generated code">
                <files-in-set>
                    <file-pattern>src/**/*_generated.c</file-pattern>
                </files-in-set>
                <behaviors>
                    <do-not-analyze-functions>
                        <function-pattern>*</function-pattern>
                    </do-not-analyze-functions>
                    <show-results value="false"/>
                </behaviors>
            </fileset>
        </classification>
    </specification>

  2. Save the classification file as exclude_generated_files.xml. Specify this classification file with the option -classification:

    polyspace-bug-finder -sources src\utils.c,src\utils_generated.c -I inc\ -classification exclude_generated_files.xml
    Or:
    polyspace-bug-finder-server -sources src\utils.c,src\utils_generated.c -I inc\ -classification exclude_generated_files.xml
    You no longer see the defect in the file utils_generated.c.

Version History

Introduced in R2023a