MISRA C:2012 Checks

You can check that your model or subsystem has a likelihood of generating MISRA C:2012 compliant code.

See Also

Check usage of Assignment blocks

Check ID: mathworks.misra.AssignmentBlocks

Identify Assignment blocks that do not have block parameter Action if any output element is not assigned set to Error or Warning.

Description

This check applies to the Assignment block that is available in the Simulink block library under Simulink > Math Operations.

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications, as well as code that complies with the CERT C, CWE, ISO/IEC TS 17961 standards.

Available with Embedded Coder® and Simulink® Check™.

Results and Recommended Actions

ConditionRecommended Action
The model or subsystem might contain Assignment blocks with incomplete array initialization that do not have block parameter Action if any output element is not assigned set to Error or Warning.

Set block parameter Action if any output element is not assigned to one of the recommended values:

  • Error, if Assignment block is not in an Iterator subsystem.

  • Warning, if Assignment block is in an Iterator subsystem.

Capabilities and Limitations

  • Runs on library models.

  • Analyzes content of library linked blocks.

  • Analyzes content in masked subsystems.

  • If you have a Simulink Check license, allows exclusions of blocks and charts.

Edit-Time Checking.  This check is supported by edit-time checking. However, the following check condition is not supported because edit-time checking is unable to determine whether the Assignment block is in an Iterator subsystem.

Set block parameter Action if any output element is not assigned to one of the recommended values:

  • Error, if Assignment block is not in an Iterator subsystem.

  • Warning, if Assignment block is in an Iterator subsystem.

See Also

Check for blocks not recommended for MISRA C:2012

Check ID: mathworks.misra.BlkSupport

Identify blocks that are not supported or recommended for MISRA C:2012 compliant code generation.

Description

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action

Lookup Table blocks using cubic spline interpolation or extrapolation methods were found in the model or subsystem. Specific blocks are:

Consider other interpolation and extrapolation methods for the Lookup Table blocks.

Deprecated Lookup Table blocks were found in the model or subsystem. Specific blocks are:

  • Lookup Table

  • Lookup Table (2-D)

Consider replacing the deprecated Lookup Table blocks.
S-Function Builder blocks were found in the model or subsystem.Consider replacing the S-Function Builder blocks with blocks recommended for production.
From Workspace blocks were found in the model or subsystemConsider replacing the From Workspace blocks with blocks recommended for production.

String blocks were found in the model or subsystem. Specific blocks are:

Consider replacing the String blocks with blocks recommended for production.

Capabilities and Limitations

You can:

  • Run this check on your library models.

  • Analyzes content of library linked blocks.

  • Analyzes content in masked subsystems.

  • Exclude blocks and charts from this check if you have a Simulink Check license.

Edit-Time Checking.  This check is supported by edit-time checking.

See Also

Check for unsupported block names

Check ID: mathworks.misra.BlockNames

Identify block names containing /.

Description

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action
Block names containing / were found in the model or subsystem.Remove / from the block name.

Capabilities and Limitations

  • Runs on library models.

  • Analyzes content of library linked blocks.

  • Analyzes content in masked subsystems.

  • If you have a Simulink Check license, allows exclusions of blocks and charts.

Edit-Time Checking.  This check is supported by edit-time checking.

See Also

Check configuration parameters for MISRA C:2012

Check ID: mathworks.misra.CodeGenSettings

Identify configuration parameters that can impact MISRA C:2012 compliant code generation.

Description

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action
Math and Data Types
Configuration parameter Use division for fixed-point net slope computation is not set to On or Use division for reciprocals of integers only.Set Use division for fixed-point net slope computation to On or Use division for reciprocals of integers only.

Configuration parameter Inf or NaN block output is set to None or error and Support non-finite numbers is set to on.

Configuration parameter Inf or NaN block output is set to None and Support non-finite numbers is set to off.

When Support non-finite numbers is:

  • on, set Inf or NaN block output to warning

  • off, set Inf or NaN block output to warning or error

Configuration parameter Model Verification block enabling is set to Use local settings or Enable All.Set Model Verification block enabling to Disable All.
Configuration parameter Undirected event broadcasts is set to none or warning.Set Undirected event broadcasts to error.
Configuration parameter Wrap on overflow is set to NoneSet configuration parameter Wrap on overflow to warning or error.
Hardware Implementation
Configuration parameter Production hardware signed integer division rounds to is set to UndefinedSet Production hardware signed integer division rounds to to Zero or Floor.
Configuration parameter Shift right on a signed integer as arithmetic shift is selected.Clear Shift right on a signed integer as arithmetic shift.
Simulation Target
Configuration parameter Compile-time recursion limit for MATLAB functions is set to a value other than 0.Set Compile-time recursion limit for MATLAB functions to 0.
Configuration parameter Dynamic memory allocation in MATLAB functions is selected.Clear Dynamic memory allocation in MATLAB functions.
Configuration parameter Enable run-time recursion for MATLAB functions is selected.Clear Enable run-time recursion for MATLAB functions.
Code Generation

Configuration parameter Bitfield declarator type specifier is set to uchar_T when any of these parameters are selected:

  • Pack Boolean data into bitfields

  • Use bitsets for storing state configuration

  • Use bitsets for storing Boolean data

Set Bitfield declarator type specifier to uint_T.
Configuration parameter Casting Modes is not set to Standards Compliant.Set Casting Modes to Standards Compliant.
Configuration parameter Code replacement library is not set to None or AUTOSAR 4.0.

Set Code replacement library to None or AUTOSAR 4.0

Configuration parameter External mode is selected.Clear External mode.
Configuration parameter Generate shared constants is selected.Clear Generate shared constants.

Configuration parameter Include comments is cleared.

Select Include comments.
Configuration parameter MAT-file logging is selected.

Clear MAT-file logging

For ERT-based target systems, configuration parameter MATLAB user comments is cleared.Select MATLAB user comments.
A value for configuration parameter Maximum identifier length is not provided.Set the value to the implementation-dependent limit. The default is 31.
Configuration parameter Parenthesis level is not set to Maximum (Specify precedence with parentheses).Set Parentheses level to Maximum (Specify precedence with parentheses).

For ERT-based target systems, configuration parameter Preserve static keyword in function declarations is cleared when File packaging format is set to Compact or Compact (with separate data file)

Select Preserve static keyword in function declarations.
Configuration parameter Replace multiplications by powers of two with signed bitwise shifts is selected.Clear Replace multiplications by powers of two with signed bitwise shifts.
Configuration parameter Shared code placement is set to Auto.

Set Shared code placement to Shared location

For ERT-based target systems, configuration parameter Support continuous time is selected Clear Support continuous time.
For ERT-based target systems, configuration parameter Support non-inlined S-functions is selected Clear Support non-inlined S-functions.
Configuration parameter System-generated identifiers is set to Classic.Set System-generated identifiers to Shortened.
Configuration parameter System target file is set to a GRT-based target.Set System target file to an ERT-based target.
Configuration parameter Use dynamic memory allocation for model initialization is selected when Code Interface Packaging is set to Reusable Function.

Clear Use dynamic memory allocation for model initialization.

Note

Select only when Code Interface Packaging is set to Reusable Function.

Action Results

Clicking Modify All changes the parameter values to the recommended values.

Note

When you click Modify All for models with a GRT-based target, the Model Advisor does not update the System target file configuration parameter to an ERT-based system.

Parameter subchecks depend on the results of the parameter noted with D in the results table. When the result is D-Warning, the Current Value column in the results table states Prerequisite constraint not met for the subchecks. After you change the parameter, rerun the check.

Note

Some subchecks are specific to configuration parameters for ERT-based systems. These parameters are not updated when you click Modify All unless you change the model to an ERT-based system.

Capabilities and Limitations

This check does not review referenced models.

See Also

Check for equality and inequality operations on floating-point values

Check ID: mathworks.misra.CompareFloatEquality

Identify equality and inequality operations on floating-point values.

Description

The check flags sources causing equality or inequality operations on floating-point values.

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications, as well as code that complies with the CERT C and CWE standards.

The check does not flag blocks with equality or inequality operations on floating-point values if they are justified with a Polyspace® annotation. When you run the check, the Blocks with justification table lists blocks with equality or inequality operations that have a justification.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action

Model object has an equality or inequality operation on a floating-point value.

Consider using non-floating-point values for equality or inequality operations.

Capabilities and Limitations

You can:

  • Exclude blocks and charts from this check if you have a Simulink Check license.

See Also

Check for bitwise operations on signed integers

Check ID: mathworks.misra.CompliantCGIRConstructions

Identify Simulink blocks that contain bitwise operations on signed integers.

Description

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications, as well as code that complies with the CERT C and CWE standards.

Available with Embedded Coder and Simulink Check.

This check requires a Stateflow® license when Stateflow is used in the model.

Results and Recommended Actions

ConditionRecommended Action
The model has blocks that contain bitwise operations on signed integers.Consider using unsigned integers for bitwise operations.

Capabilities and Limitations

You can:

  • The check assumes that code is generated for the whole model. When code is generated by a subsystem build or export functions, the check can product incorrect results.

  • Exclude blocks and charts from this check if you have a Simulink Check license.

See Also

Check for recursive function calls

Check ID: mathworks.misra.RecursionCompliance

Identify recursive function calls in Stateflow charts.

Description

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications. The check flags charts that have recursive function calls.

Available with Embedded Coder and Simulink Check.

This check requires a Stateflow license.

Results and Recommended Actions

ConditionRecommended Action

Chart has a recursive function call.

Remove recursive function call.

See Also

Check for switch case expressions without a default case

Check ID: mathworks.misra.SwitchDefault

Identify switch case expressions that do not have a default case.

Description

The check flags model objects that have switch case expressions without a default case.

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications, as well as code that complies with the CERT C, CWE, ISO/IEC TS 17961 standards.

The check does not flag blocks without default cases if they are justified with a Polyspace annotation. When you run the check, the Blocks with justification table lists blocks without default cases that have a justification.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action

Model object has a switch case expression without a default case.

For Switch Case blocks, consider selecting block parameter Show default case to explicitly specify a default case.

Capabilities and Limitations

You can:

  • Run this check on your library models.

  • Exclude blocks and charts from this check if you have a Simulink Check license.

Edit-Time Checking.  This check is supported by edit-time checking.

See Also

Check for blocks not recommended for C/C++ production code deployment

Check ID: mathworks.codegen.PCGSupport

Identify blocks not supported by code generation or not recommended for C/C++ production code deployment.

Description

This check partially identifies model constructs that are not recommended for C/C++ production code generation. For Simulink Coder™ and Embedded Coder, these model construct identities appear in tables of Simulink Block Support (Simulink Coder).

In some instances, this check flags blocks that are supported for code generation. For these blocks, you should review the footnote information that is provided in the support notes and adhere to the recommended action provided by the Model Advisor.

Following the recommendations of this check increases the likelihood of generating code that complies with the CERT C, CWE, and ISO/IEC TS 17961 standards.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action
The model or subsystem contains blocks that should not be used for production code deployment.Consider replacing the blocks listed in the results. Click an element from the list of questionable items to locate condition.
The model or subsystem contains blocks that are supported but not recommended for production code generation.Review the support notes and adhere to the recommended action provided by the Model Advisor.

Capabilities and Limitations

You can:

  • Run this check on your library models.

  • Analyze content of library linked blocks.

  • Analyze content in masked subsystems.

  • Exclude blocks and charts if you have a Simulink Check license.

Edit-Time Checking

This check is supported by edit-time checking.

See Also

Check for missing error ports for AUTOSAR receiver interfaces

Check ID: mathworks.misra.AutosarReceiverInterface

Identify AUTOSAR receiver interface inports that do not have matching error ports.

Description

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications. The check flags AUTOSAR receiver interfaces inports that are missing error ports. The following table identifies the AUTOSAR data access mode types for receiver interface ports that are flagged by the check when the corresponding error port is missing.

AUTOSAR Data Access Mode TypeFlagged by Check?
ImplicitReceiveYes
ExplicitReceiveYes
QueuedExplicitReceiveNo
ErrorStatusNo
ModeReceiveNo
IsUpdatedNo
EndToEndReadYes
ExplicitReceiveByValNo
otherwiseNo

The check does not flag missing error ports when they are justified with a Polyspace annotation. When you run the check, the Blocks with justification table lists the missing error ports that have a justification.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action

AUTOSAR receiver interface inport does not have a matching error port.

Add missing error port and map to the corresponding AUTOSAR receiver interface inport.

AUTOSAR receiver interface ports do not have a matching error port when data access mode is ImplicitReceive, ExplicitReceive, or EndToEndRead.

Add missing error port and map to the corresponding AUTOSAR receiver interface inport.

Capabilities and Limitations

You can:

  • Analyzes top layer/root level models.

  • Exclude blocks and charts from this check if you have a Simulink Check license.

See Also

Check for missing const qualifiers in model functions

Check ID: mathworks.misra.ModelFunctionInterface

Identify missing const qualifiers in input data pointers.

Description

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications. The check flags input data pointers that do not have a const qualifier.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action
A const qualifier is not defined for the input data pointer.Consider adding a const qualifier to the input data pointer.

See Also

Check integer word length

Check ID: mathworks.misra.IntegerWordLengths

Identify integer word lengths that do not comply with hardware implementation settings

Description

The check flags integers whose word lengths exceed the number of bits permitted via the hardware implementation settings.

Following the recommendations of this check increases the likelihood of generating MISRA C:2012 compliant code for embedded applications, as well as code that complies with the CERT C and CWE standards.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action

Model object contains integer word lengths that are not compliant with hardware implementation settings.

Update the integer so its length does not exceed the permitted number of bits. You can view the permitted number of bits in the Configuration Parameters dialog box, on the Hardware Implementation > Device details pane.

Capabilities and Limitations

You can:

  • Exclude blocks and charts from this check if you have a Simulink Check license.

See Also

Check bus object names that are used as bus element names

Check ID: mathworks.misra.BusElementNames

Identify bus object names that are used as bus element names.

Description

Using this check increases the likelihood of generating code for embedded applications that is compliant with MISRA C:2012. The check flags instances where a Simulink.Bus object name is used as the Simulink.Bus element name.

Available with Embedded Coder and Simulink Check.

Results and Recommended Actions

ConditionRecommended Action
A bus object name is being used as a bus element name.Change either the flagged bus object name or the bus element name so that they are not identical.

See Also