- Floating point comparison with equality operators
- Cyclomatic complexity exceeds threshold
- MISRA C:2012 rules 10.x and 11.x (prevents casts to incompatible types)
Control generated C/C++ code using Mathworks tooling
2 次查看(过去 30 天)
显示 更早的评论
Hello everybody,
Please bear with me if the question may be trivial, i'm still pretty new to MATLAB and, in general, Mathworks tools.
So far, being a software engineer, i have mainly been the recipient of C/C++ code generated by Embedded Coder. It happens that this code sometimes has various undesired characteristics, eg:
- Huge arrays (like millions of elements)
- Wild C-style casts (for example casting to void*)
- Floating point numbers direct comparison (ie with ==)
- Very high cyclomatic complexity
I can detect this kind of problems with tools external to the Mathworks' ones, but this means i can only do it "after the fact".
Ideally i would like also the provider of the code to be able to detect them.
Is there a Mathworks tool capable of doing this?
I am thinking, for example, to the Polyspace ones or some "static analysis" app available in Matlab.
It would be fantastic to be able to also introduce "custom rules" for this static analysis.
Thanks in advance!
0 个评论
采纳的回答
Anirban
2022-1-24
编辑:Anirban
2022-1-25
The Polyspace static analysis tools are meant exactly for the kind of issues you are talking about, but even in Embedded Coder, it is possible to set up code generation to minimize/avoid some of these issues.
For instance, following the MISRA C:2012 rules 10.x and 11.x prevent C-style casts to incompatible types. Using Embedded Coder, you can generate code that is compliant with this set of rules. See Generate C/C++ Code with Improved MISRA Compliance. But with Polyspace Bug Finder, you can independently check for violations of these rules. See Check for Coding Standard Violations.
Polyspace Bug Finder has checks for all the things you mentioned:
In fact, Polyspace Bug Finder can be installed as an add-on in Simulink and run on the generated code. See Run Polyspace Analysis on Code Generated from Embedded Coder.
3 个评论
Anirban
2022-1-25
编辑:Anirban
2022-1-25
Polyspace does provide quite a few more complex customizations and every release, new customization capabilities are added. If you want specific customizations, they can be requested through Technical Support. For instance, you can define your own list of keywords to forbid from the code and then have Polyspace Bug Finder flag uses of those keywords or have checks on standard libraries be extended to checks on custom libraries, and so on.
As for the specific case of arrays exceeding a certain size, there is no check yet. The closest that is available in Code Prover is stack size estimation. You can put a threshold on the stack size usage and identify cases where the threshold is violated. So, if there are huge local arrays, those would be flagged. Since global arrays do not use the stack, this check will not apply to those.
Note: The analysis actually errors out for very large objects. See this troubleshooting for the error. But this error has a very high threshold, so it would not serve your needs.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Polyspace Products for Ada 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!