MathWorks® evaluates C code generated by Embedded Coder® from Simulink® and Stateflow® against the MISRA C:2012 coding standards. The results from this effort are available in these compliance summary tables. These tables identify:
Methods used to obtain compliance:
Compliant: Compliance to the rule/directive is achieved through adherence to the code generation process, modeling guidelines, or Model Advisor checks. When applicable, there are explanatory notes that provide information relevant to compliance methods or actions that you can perform to satisfy the directive or rule.
Deviation: The rule or directive is not compliant.
Whether the Polyspace® MISRA C:2012 Checker supports the rule or directive.
You can use these tables when preparing the MISRA C:2012 compliance statement for your project as required per section 5.3 of the MISRA C:2012 Guidelines for the Use of C Language in Critical Systems document. These tables align with the published MISRA C:2012 rule and directives tables.
"Implementation" MISRA C:2012 Directives
Directive | Category | Compliance | Polyspace Support? |
---|---|---|---|
1.1 | Required | Compliant:
| Yes, partially supported |
"Compilation and Build" MISRA C:2012 Directives
Directive | Category | Compliance | Polyspace Support? |
---|---|---|---|
2.1 | Required | Compliant | Yes |
"Requirements Traceability" MISRA C:2012 Directives
Directive | Category | Compliance | Polyspace Support? |
---|---|---|---|
3.1 | Required | Compliant:
| No |
"Code Design" MISRA C:2012 Directives
Directive | Category | Compliance | Polyspace Support? |
---|---|---|---|
4.1 | Required | Compliant:
| Yes |
4.3 | Required | Compliant:
| No |
4.6 | Required | Not Applicable. See Explanatory Note for Directive 4.6 | N/A |
4.7 | Required | Compliant:
Deviation:
| Yes[a] |
4.10 | Required | Compliant | Yes |
4.11 | Required | Compliant:
| Yes |
4.12 | Required | Compliant:
| No |
[a] The Polyspace MISRA C:2012 Checker might flag Directive 4.7 as a Rule 17.7 violation (Polyspace Bug Finder) for user-defined functions when there is no knowledge about whether the return value contains error information. |
"Standard C Environment" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
1.1 | Required | Compliant | Yes |
1.3 | Required | Compliant | Yes |
"Unused Code" MISRA C:2012 Rules
"Comments" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
3.1 | Required | Compliant:
| Yes |
3.2 | Required | Compliant | Yes |
"Character Sets and Lexical Conventions" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
4.1 | Required | Compliant | Yes |
"Identifiers" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
5.1 | Required | Compliant:
| Yes |
5.2 | Required | Compliant:
| Yes |
5.4 | Required | Compliant:
| Yes |
5.5 | Required | Compliant:
| Yes |
5.6 | Required | Compliant:
| Yes |
5.7 | Required | Compliant:
| Yes |
5.8 | Required | Compliant:
| Yes |
"Types" MISRA C:2012 Rules
"Literals and Constants" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
7.4 | Required | Compliant | Yes |
"Declarations and Definitions" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
8.1 | Required | Compliant | Yes |
8.2 | Required | Compliant | Yes |
8.3 | Required | Compliant | Yes |
8.6 | Required | Compliant | Yes |
8.8 | Required | Compliant | Yes |
8.10 | Required | Compliant | Yes |
8.12 | Required | Compliant:
| Yes |
"Initialization" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
9.1 | Mandatory | Compliant:
| Yes |
9.4 | Required | Compliant | Yes |
"Pointer Type Conversion" MISRA C:2012 Rules
"Expressions" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
12.2 | Required | Compliant | Yes |
"Side Effects" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
13.1 | Required | Compliant | Yes |
13.2 | Required | Compliant:
| Yes |
13.5 | Required | Compliant:
Deviation:
| Yes |
13.6 | Mandatory | Compliant | Yes |
"Control Statement Expressions" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
14.3 | Required | Compliant:
| Yes |
"Control Flow" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
15.6 | Required | Compliant | Yes |
"Functions" MISRA C:2012 Rules
"Pointers and Arrays" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
18.1 | Required | Compliant | Yes |
18.2 | Required | Compliant | Yes |
18.3 | Required | Compliant | Yes |
18.6 | Required | Compliant | Yes |
18.7 | Required | Compliant | Yes |
18.8 | Required | Compliant | Yes |
"Overlapping Storage" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
19.1 | Mandatory | Compliant | Yes |
"Preprocessing Directives" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
20.2 | Required | Compliant | Yes |
20.3 | Required | Compliant | Yes |
20.4 | Required | Compliant | Yes |
20.6 | Required | Compliant | Yes |
20.7 | Required | Compliant | Yes |
20.9 | Required | Compliant | Yes |
20.11 | Required | Compliant | Yes |
20.12 | Required | Compliant | Yes |
20.13 | Required | Compliant | Yes |
20.14 | Required | Compliant | Yes |
"Standard Libraries" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
21.1 | Required | Compliant | Yes |
21.2 | Required | Compliant:
| Yes |
21.3 | Required | Compliant:
| Yes |
21.4 | Required | Compliant | Yes |
21.6 | Required | Compliant:
| Yes |
21.7 | Required | Compliant | Yes |
21.8 | Required | Compliant | Yes |
21.9 | Required | Compliant | Yes |
21.10 | Required | Compliant | Yes |
21.11 | Required | Compliant | Yes |
"Resources" MISRA C:2012 Rules
Rule | Category | Compliance | Polyspace Support? |
---|---|---|---|
22.1 | Required | Compliant | Yes |
22.2 | Mandatory | Compliant | Yes |
22.3 | Required | Compliant | Yes |
22.4 | Mandatory | Compliant | Yes |
22.5 | Mandatory | Compliant | Yes |
22.6 | Mandatory | Compliant | Yes |
These explanatory notes are referenced from the MISRA C:2012 Compliance Information Summary Tables.
Information about the implementation-defined behavior for Embedded Coder is available in Configure Run-Time Environment Options . Compiler documentation is out of scope.
Character set encoding is managed by using the
SavedCharacterEncoding
model parameter. For additional
information, including a list of supported character encodings, see slCharacterEncoding
.
Configure the integer division method in the Model Configuration Parameters dialog box, on the Hardware Implementation pane. For additional information, see Configure Run-Time Environment Options
Embedded Coder generates #pragma
when the user:
In both instances, you are responsible for documenting the intended
use of the #pragma
. For more information, see Control Data and Function Placement in Memory by Inserting Pragmas.
To enable the generation of bitfields:
Select at least one of these model configuration parameters:
Pack Boolean data into bitfields. This parameter is available only for ERT-based system target files.
Create a custom storage class with defined bitfields. See Create Storage Classes by Using the Custom Storage Class Designer for more information.
You can link requirements model elements. These links are included in the generated C code to provide traceability from a requirements document, to the model elements, and to the generated code. For additional information, see View Linked Requirements in Models and Blocks and Link Blocks and Requirements (Simulink Requirements).
You can use Polyspace Bug Finder™ to identify run-time errors and Polyspace Code Prover™ to prove the absence of run-time errors. For information, see:
Configure and Run Analysis (Polyspace Code Prover)
Configure and Run Analysis (Polyspace Bug Finder)
Simulink Design Verifier can be used to detect design errors at the model level. For more information, see Run a Design Error Detection Analysis (Simulink Design Verifier).
Embedded Coder does not directly call assembly language code. You can add calls to assembly language functions through S-functions, code replacement libraries, Stateflow, and in MATLAB® blocks. These calls are documented as calls to External C Functions. In these cases, you are responsible for encapsulation.
For additional information, see:
Embedded Coder replaces basic data types with typedefs types, which are compatible with Directive 4.6. A guideline is not required because this behavior is default behavior in Embedded Coder. For additional information, see Replace and Rename Data Types to Conform to Coding Standards and Typedefs.
The requirements of this directive are satisfied by:
“Demonstrate statically that the input parameters can never take invalid values”.
You can use Polyspace Code Prover to analyze parameter ranges and prove the absence of run-time errors caused by out-of-range values. For additional information, see Run Polyspace Analysis on Code Generated with Embedded Coder (Polyspace Code Prover).
Embedded Coder is configurable to limit the number of characters imposed by the implementation. For additional information, see Maximum identifier length.
To ensure unique names for different types of variables (local scope variables, global scope variables, macros, and so on), implement a naming convention. For additional information, see Model Configuration Parameters: Code Generation Symbols.
Embedded Coder supports the use of enumerated data. The file used to define the enumeration can be either manually or automatically generated. Files defining enumerations generated by Embedded Coder are compliant with MISRA C:2012 Rule 8.12 by design. If you manually create the definition file, you are responsible for ensuring compliance. For additional information, see Use Enumerated Data in Simulink Models.
Embedded Coder does not directly create data of type char. Data of char type can be introduced by user-defined S-functions, code replacement libraries, and custom storage classes. In this case, limit the usage of plain char to:
Plain char type for character values
Signed and unsigned char type for numeric values