MISRA C:2012 Checks
You can check that your model or subsystem has a likelihood of generating MISRA C:2012 compliant code.
See Also
Qualified Model Advisor Checks(IEC Certification Kit)
Qualified Model Advisor Checks(DO Qualification Kit)
Check usage of Assignment blocks
Check ID:mathworks.misra.AssignmentBlocks
IdentifyAssignmentblocks that do not have block parameterAction if any output element is not assignedset toErroror警告.
Description
This check applies to theAssignment块模型块libr可用金宝appary under金宝app>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金宝app®Check™.
Results and Recommended Actions
Condition | Recommended Action |
---|---|
The model or subsystem might containAssignmentblocks with incomplete array initialization that do not have block parameterAction if any output element is not assignedset toErroror警告. | Set block parameterAction if any output element is not assignedto one of the recommended values:
|
Capabilities and Limitations
Runs on library models.
Analyzes content of library linked blocks.
Analyzes content in masked subsystems.
If you have aSimulink Checklicense, 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 theAssignmentblock is in an Iterator subsystem.
Set block parameterAction if any output element is not assignedto one of the recommended values:
Error, ifAssignmentblock is not in an Iterator subsystem.
警告, ifAssignmentblock is in an Iterator subsystem.
See Also
MISRA C:2012, Rule 9.1
ISO/IEC TS 17961: 2013, uninitref
CERT C, EXP33-C
CWE, CWE-908
MISRA C(Embedded Coder)
Check for blocks not recommended for MISRA C:2012
Check ID:mathworks.misra.BlkSupport
确定块不是苏pported 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 andSimulink Check.
Results and Recommended Actions
Condition | Recommended 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:
|
Consider replacing the deprecated Lookup Table blocks. |
S-Function Builderblocks were found in the model or subsystem. | Consider replacing the S-Function Builder blocks with blocks recommended for production. |
From Workspaceblocks were found in the model or subsystem | Consider 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 aSimulink Checklicense.
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 andSimulink Check.
Results and Recommended Actions
Condition | Recommended 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 aSimulink Checklicense, allows exclusions of blocks and charts.
Edit-Time Checking.This check is supported by edit-time checking.
See Also
MISRA C:2012, Rule 3.1
MISRA C(Embedded Coder)
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 andSimulink Check.
Results and Recommended Actions
Condition | Recommended Action |
---|---|
Math and Data Types | |
Configuration parameterUse division for fixed-point net slope computationis not set toOn orUse division for reciprocals of integers only . |
SetUse division for fixed-point net slope computationtoOn orUse division for reciprocals of integers only . |
Configuration parameterInf or NaN block outputis set to Configuration parameterInf or NaN block outputis set to |
WhenSupport non-finite numbersis:
|
Configuration parameterModel Verification block enablingis set toUse local settings orEnable All . |
SetModel Verification block enablingtoDisable All . |
Configuration parameterUndirected event broadcastsis set tonone orwarning . |
SetUndirected event broadcaststoerror . |
Configuration parameterWrap on overflowis set toNone |
Set configuration parameterWrap on overflowtowarning orerror . |
硬件Implementation | |
Configuration parameterProduction hardware signed integer division rounds tois set toUndefined |
SetProduction hardware signed integer division rounds totoZero orFloor . |
Configuration parameterShift right on a signed integer as arithmetic shift被选中。 | ClearShift right on a signed integer as arithmetic shift. |
Simulation Target | |
Configuration parameterCompile-time recursion limit for MATLAB functionsis set to a value other than0 . |
SetCompile-time recursion limit for MATLAB functionsto0 . |
Configuration parameterDynamic memory allocation in MATLAB functions被选中。 | ClearDynamic memory allocation in MATLAB functions. |
Configuration parameterEnable run-time recursion for MATLAB functions被选中。 | ClearEnable run-time recursion for MATLAB functions. |
Code Generation | |
Configuration parameterBitfield declarator type specifieris set to
|
SetBitfield declarator type specifiertouint_T . |
Configuration parameterCasting Modesis not set toStandards Compliant . |
SetCasting ModestoStandards Compliant . |
Configuration parameterCode replacement libraryis not set toNone orAUTOSAR 4.0 . |
SetCode replacement libraryto |
Configuration parameterExternal mode被选中。 | ClearExternal mode. |
Configuration parameterGenerate shared constants被选中。 | ClearGenerate shared constants. |
Configuration parameterInclude commentsis cleared. |
SelectInclude comments. |
Configuration parameterMAT-file logging被选中。 | ClearMAT-file logging |
For ERT-based target systems, configuration parameterMATLAB user commentsis cleared. | SelectMATLAB user comments. |
A value for configuration parameterMaximum identifier lengthis not provided. | Set the value to the implementation-dependent limit. The default is31 . |
Configuration parameterParentheses levelis not set toStandards(Parentheses for Standards Compliance) orMaximum(Specify precedence with parentheses) . |
SetParentheses leveltoStandards(Parentheses for Standards Compliance) orMaximum(Specify precedence with parentheses) . |
For ERT-based target systems, configuration parameterPreserve static keyword in function declarationsis cleared whenFile packaging formatis set to |
SelectPreserve static keyword in function declarations. |
Configuration parameterReplace multiplications by powers of two with signed bitwise shifts被选中。 | ClearReplace multiplications by powers of two with signed bitwise shifts. |
Configuration parameterShared code placementis set toAuto . |
SetShared code placementto |
For ERT-based target systems, configuration parameterSupport continuous timeis selected | ClearSupport continuous time. |
For ERT-based target systems, configuration parameterSupport non-inlined S-functionsis selected | ClearSupport non-inlined S-functions. |
Configuration parameterSystem-generated identifiersis set toClassic . |
SetSystem-generated identifierstoShortened . |
Configuration parameterSystem target fileis set to a GRT-based target. | SetSystem target fileto an ERT-based target. |
Configuration parameterUse dynamic memory allocation for model initializationis selected whenCode Interface Packagingis set toReusable Function . |
ClearUse dynamic memory allocation for model initialization. Note Select only whenCode Interface Packagingis set to |
Action Results
ClickingModify Allchanges the parameter values to the recommended values.
Note
When you clickModify Allfor models with a GRT-based target, the Model Advisor does not update theSystem target fileconfiguration parameter to an ERT-based system.
Parameter subchecks depend on the results of the parameter noted withDin the results table. When the result isD-Warning,Current Valuecolumn in the results table statesPrerequisite constraint not metfor 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 clickModify Allunless 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, theBlocks with justificationtable lists blocks with equality or inequality operations that have a justification.
Available with Embedded Coder andSimulink Check.
Note
Stateflow®license is needed if the model contains Stateflow elements.
Results and Recommended Actions
Condition | Recommended Action |
---|---|
Model object has an equality or inequality operation on a floating-point value. |
考虑使用non-floating-point值相等ity or inequality operations. |
Capabilities and Limitations
You can:
Exclude blocks and charts from this check if you have aSimulink Checklicense.
See Also
MISRA C:2012, Dir 1.1
CERT C, FLP02-C
CWE, CWE-1077
Annotate Code and Hide Known or Acceptable Results(Polyspace Bug Finder)
MISRA C(Embedded Coder)
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 andSimulink Check.
Note
Stateflow license is needed if the model contains Stateflow elements.
Results and Recommended Actions
Condition | Recommended 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 aSimulink Checklicense.
See Also
MISRA C:2012, Rule 10.1
CERT C, INT13-C
CWE, CWE-682
hisl_0060: Configuration parameters that improve MISRA C:2012 compliance
MISRA C(Embedded Coder)
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 andSimulink Check.
Note
Stateflow license is needed if the model contains Stateflow elements.
Results and Recommended Actions
Condition | Recommended Action |
---|---|
Chart has a recursive function call. |
Remove recursive function call. |
See Also
MISRA C:2012, Rule 17.2
Avoid Unwanted Recursion in a Chart(Stateflow)
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, theBlocks with justificationtable lists blocks without default cases that have a justification.
Available with Embedded Coder andSimulink Check.
Results and Recommended Actions
Condition | Recommended Action |
---|---|
Model object has a switch case expression without a default case. |
ForSwitch Caseblocks, consider selecting block parameterShow default caseto 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 aSimulink Checklicense.
Edit-Time Checking.This check is supported by edit-time checking.
See Also
MISRA C:2012, Rule 16.4
ISO/IEC TS 17961: 2013, swtchdflt
CERT C, MSC01-C
CWE, CWE-478
Annotate Code and Hide Known or Acceptable Results(Polyspace Bug Finder)
MISRA C(Embedded Coder)
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. ForSimulink Coder™and Embedded Coder, these model construct identities appear in tables ofSimulink 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 andSimulink Check.
Results and Recommended Actions
Condition | Recommended 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 aSimulink Checklicense.
Edit-Time Checking
This check is supported by edit-time checking.
See Also
Use Blocks and Products Supported for Code Generation(Simulink Coder)
Secure Coding Standards(Embedded Coder)Secure Coding(Embedded Coder)
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 Type | Flagged by Check? |
---|---|
ImplicitReceive |
Yes |
ExplicitReceive |
Yes |
QueuedExplicitReceive |
No |
ErrorStatus |
No |
ModeReceive |
No |
IsUpdated |
No |
EndToEndRead |
Yes |
ExplicitReceiveByVal |
No |
otherwise |
No |
The check does not flag missing error ports when they are justified with a Polyspace annotation. When you run the check, theBlocks with justificationtable lists the missing error ports that have a justification.
Available with Embedded Coder andSimulink Check.
Results and Recommended Actions
Condition | Recommended 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 isImplicitReceive ,ExplicitReceive , orEndToEndRead . |
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 aSimulink Checklicense.
See Also
MISRA C: 2012, Directive 4.7
MISRA C(Embedded Coder)
Annotate Code and Hide Known or Acceptable Results(Polyspace Bug Finder)
Configure AUTOSAR Elements and Properties(AUTOSAR Blockset)
AUTOSAR Component Configuration(AUTOSAR Blockset)
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 andSimulink Check.
Results and Recommended Actions
Condition | Recommended Action |
---|---|
A const qualifier is not defined for the input data pointer. | Consider adding a const qualifier to the input data pointer. |
See Also
MISRA C:2012, Rule 8.13
MISRA C(Embedded Coder)
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 andSimulink Check.
Note
Stateflow license is needed if the model contains Stateflow elements.
Results and Recommended Actions
Condition | Recommended 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硬件Implementation>Device detailspane. |
Capabilities and Limitations
You can:
Exclude blocks and charts from this check if you have aSimulink Checklicense.
See Also
MISRA C:2012, Rule 10.1
CERT C, INT13-C
CWE, CWE-682
MISRA C(Embedded Coder)
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 andSimulink Check.
Results and Recommended Actions
Condition | Recommended 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
MISRA C:2012, Rule 5.6
MISRA AC AGC, Rule 5.3
MISRA C(Embedded Coder)