MISRA rules violations of Generated Code for Embedded Coder
24 ビュー (過去 30 日間)
Ismael Lafoz 2018 年 9 月 19 日
回答済み: Michael Burke 2019 年 12 月 2 日
I am using Embedded Coder to generate C source code from a Simulink model, selecting MISRA-C compliance objective, and when I run Polyspace analysis, I get lots of MISRA rules violations.
How can this be fixed?
回答 (3 件)
Anirban 2018 年 10 月 4 日
In addition to the previous answer, another possibility can be that you ran Polyspace for MISRA rules meant for handwritten code and not generated code. MISRA C:2012 (Appendix E) moves several rules from the Required category to the Advisory or Readability category if the code is generated from a model. If you ran Polyspace with the Required subset of MISRA C:2012 checkers for handwritten code, you might get more violations compared to the Required subset for generated code.
To run Polyspace with the MISRA C:2012 checker for generated code, use the Polyspace option Use generated code requirements ( -misra3-agc-mode). See documentation for the option . If you run Polyspace directly from Simulink, this option gets enabled automatically.
Prakhar Jain 2018 年 9 月 25 日
The rules of MISRA C:2012 often gets updated with newer releases and a variety of reasons can be responsible for the violation. Please find the below rules for violation scenarios which has been made for the later releases and may be causing violations.
1) If there are identifiers beginning with underscore
2) If a reserved identifier or macro name is declared
Note: The above possible workaround may/may not work for your case.
In case you only expect to remove the warnings, you can always uncheck rules in the Coding Rules & Code Metrics in the configuration pane. Follow the below steps:
1) Open configuration pane
2) Click on the edit button as seen in the screenshot in red
3) Go to let's say rule no 21.2 and uncheck it as shown in screenshot in red
Here is an attached link for the same.
The above remove warnings can also be unchecked for other rule violations if required.
Michael Burke 2019 年 12 月 2 日
Note: one thing that you should look at is the model configuration parameters. This link provides a good overview of what you should do to configure your model:
Code Verification Polyspace Code Prover Configure and Run Analysis Set Up Code Prover Analysis on Desktop Code Prover Analysis in Simulink
Find more on Code Prover Analysis in Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!