Main Content

Calculate stack usage (-stack-usage)

Compute and display the estimates of stack usage

Since R2022a

Description

This option applies to Code Prover only.

Specify that Polyspace® must estimate and display the stack usage of your source code. The estimates include:

Set Option

User interface (desktop products only): In your project configuration, the option is on the Check Behavior subnode of the Code Prover Verification node.

User interface (Polyspace Platform, desktop products only): In your project configuration, the option is on the Static Analysis tab on the Run Time Errors > Check Behavior node.

Command line and options file: Use the option -stack-usage. See Command-Line Information.

Why Use This Option

Estimating the stack usage of your code is necessary because:

  • Underestimating the stack usage of your code results in a stack overflow.

  • Overestimating the stack usage results in wasted memory.

Obtain the estimated stack usage of your code by using the option -stack-usage to avoid a stack overflow or wasted memory. This option is especially important for safety critical applications where the available stack size must accommodate the worst-case stack usage.

Settings

On

Polyspace computes and displays stack usage metrics on the Results List pane.

Off (default)

Polyspace does not compute stack usage metrics.

Tips

  • If you want to compute only the stack usage of your code, run verification up to the Source Compliance Checking phase. See Verification level (-to).

  • A Code Prover analysis computes the stack usage metrics after the source compliance checking phase. If you stop a Code Prover verification before source compliance checking, the stack usage metrics are not reported.

  • This option calculates code metrics that are related to stack usage. Use Bug Finder to calculate the other code metrics. See Calculate code metrics (-code-metrics).

  • Using this option together with -code-metrics option results in an error. The option -code-metrics will be removed from Code Prover in a future release. To compute the code metrics, use Bug Finder instead. See Migrate Code Prover Workflows for Checking Coding Standards and Code Metrics to Bug Finder.

  • If a function is not defined, Code Prover considers zero contribution to the stack size when this function is called. You can explicitly specify a stack size contribution from such stubbed functions using the option -code-behavior-specifications.

Command-Line Information

Parameter: -stack-usage
Default: Off
Example (Code Prover): polyspace-code-prover -sources file_name -stack-usage
Example (Code Prover Server): polyspace-code-prover-server -sources file_name -stack-usage

Version History

Introduced in R2022a