Main Content

Run Analysis and Review Results in Visual Studio

After you configure the Polyspace® as You Code™ plugin, you are ready to run an analysis and fix or justify any results. Before continuing this tutorial, verify that you have added example.hpp and example_source.cpp to the Quality Monitoring list.

Run Polyspace as You Code Analysis in Visual Studio

Run an analysis on example_source.cpp by using one of these methods:

  • If you set Start analysis on save, save your edited file.

  • Right-click the file and select Polyspace > Run Polyspace Analysis.

  • In the Quality Monitoring list, click the Analyze all files in the list sequentially button .

View, Fix, or Justify Results

After Polyspace runs the analysis, the filename in the Quality Monitoring view is green if there are no results and red if there are results. A number to the right of the filename indicates the number of results. View your results in the Error List pane. Open the Error List pane by clicking the filename in the Quality Monitoring list.

The Error List pane shows all results in a list. Use the filter in the Error List pane to search for specific results. Each result contains a line and column number that indicate the location in the code where Polyspace found the defect or coding rule violation. If the Error List is not open, reset the perspective by clicking Extensions > Polyspace > Open Polyspace Windows.

Click on a result to view more information about the result in the Result Details pane. Click the expander for the result in the Result Details pane to show potential fixes or justifications to apply to the result.

After Polyspace as You Code completes its analysis on example_source.cpp, open the results in the Error List pane. Use the filter to search for 6.5.1. Polyspace finds a violation of MISRA C++:2023:6.5.1 on line 9.

Click the result in the Error List to open the file where the rule violation occurs. Each result is noted in the file with a red underline. Hover over the underlined sections of code to see a list of each result associated with the underlined section.

In example.h, add this line of code on line 9 after the class definition:

int getDenominator(bool triggerError);

Save the file to run another analysis. The violation of A16-2-3 in example_source.cpp is no longer present.

With automatic analysis active, you can find and justify or fix results during the code authoring process. Each time you save changes, a Polyspace analysis begins in the background and displays any new results or removes fixed results from the list.

Justify Individual Findings

You can justify a result from the Error List pane or from the location of the violation in the code.

To add a justification to a result, right-click a result in the Error List and select Polyspace > Justify the current result. This adds an ammendable comment to your codeat the location where the code violation occurs

Adding a justification removes the result from the Error List. To show the result again, remove the justification comment and perform an analysis.

For this tutorial, after running an analysis:

  1. Locate the result for the defect integer division by zero on line 6 in the Error List.

  2. Right click the result and select Polyspace > Justify the current result.

Use Predefined Justifications

You can add a catalog of predefined justifications to Polyspace as You Code. If you use a catalog of predefined justifications, you can select a comment from the catalog to append to the justification instead of manually typing a justification comment.

Select Tools > Options and then Polyspace as You Code from the sidebar. Next to the Justification catalog text box, click Browse and navigate to your justification catalog.

In this tutorial, use the example JSON file example_catalog.json to create a justification catalog:

{
	"justifications": [
		{
		"family": "Defect",
		"acronym": "INT_ZERO_DIV",
		"comment": "This is my justification for division"
		},
		{
		"family": "Defect",
		"acronym": "INT_ZERO_DIV",
		"comment": "Alternative justification for division"
		}
	]
}

Provide the location of the catalog in the Visual Studio options.

View Header Results

When you analyze source files, Polyspace as You Code shows any header file results in the Error List pane. If a header contains a result, it is noted with a red H next to the source file in the Quality Monitoring list.

Click a header result in the Error List to navigate to the header file that contains the result. The source file analysis that caused the header result is listed in the Description column of the Error List.

After you run an analysis on the example code, open the results in the Error List pane. Use the filter to search for 19.2.1. There is a violation of MISRA C++:2023 Rule 19.2.1 in the file example.h.

Replace the example header file with this code:

#ifndef CALCULATOR_H
#define CALCULATOR_H

class Calculator {
public:
    int divide(int numerator, int denominator);

    Calculator() = default;
};

#endif // CALCULATOR_H

Save the file and run another analysis. The violation of MISRA C++:2023 Rule 19.2.1 is no longer in the results list.

Compare Results Against a Baseline

For more efficient bug fixing, compare your Polyspace as You Code single-file analysis results against a set of baseline results so you can focus on new or unreviewed results only. You can create a local baseline or download a Polyspace Bug Finder™ analysis from Polyspace Access™ to use as a baseline.

For more information on creating or downloading a baseline in Visual Studio, see Visual Studio: Configure Baseline Results in Polyspace as You Code.

See Also

Topics