Control generated C/C++ code using Mathworks tooling

2 ビュー (過去 30 日間)
fraben
fraben 2022 年 1 月 21 日
コメント済み: fraben 2022 年 1 月 26 日
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!

採用された回答

Anirban
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
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.
fraben
fraben 2022 年 1 月 26 日
Thank you Anirban, all the answers were really helpful :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet 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!

Translated by