Matlab Coder Eliminating "Dead Code"
41 views (last 30 days)
Show older comments
Hello,
I have a large Matlab application that I'm trying to convert to C++ using Matlab Coder. I've resolved errors in the code such that code generation succeeds and the modified Matlab functions as expected but the resulting C++ doesn't behave the same way as the Matlab. I'm seeing that only one of the functions that sets the output of the entrypoint is actually being converted, and even then it's not converting all of it. It only converts the code that is reachable from the values I set in "coder.typeof", not the code that is reachable from all possible values of those strings and doubles. This is not the behavior I expected and I'd like it to treat my arguments as arbitrary strings and doubles. How can I do this?
Below is a simplified version of my entrypoint function and how I'm defining the arguments to the codegen command. Only the function set_A() is being generated, not set_B() or set_C(). Thanks in advance!
string_a = coder.typeof('a', [Inf 1], [true false]);
string_b = coder.typeof('a', [Inf 1], [true false]);
double_a = coder.typeof(0, [1 1], [false false]);
double_b = coder.typeof(0, [1 1], [false false]);
% codegen -config:lib -lang:c++ myEntryPoint -args {string_a, string_b, double_a, double_b} -report
function [A, B, C] = myEntryPoint(string_a, string_b, double_a, double_b)
A = set_A();
B = set_B(string_a, double_a);
C = set_C(string_b, double_b);
end
3 Comments
dpb
about 1 hour ago
I didn't really think it would necessrily solve the issue, but thought it might have confused things with what would have expected the MATLAB function handling of the char() strings to be.
I really don't know anything about using coder and found it to be quite confusing in looking at the coder.typeof documentation, thinking I might be able to interpret the issue.
Unless somebody who really does know the details of how it uses these definitions chimes in "real soon now", I would suggest you submit this to Mathworks as an official support request/bug at <Product Support Page> as the experts can explain in more depth just how the input arguments are interpreted.
I, too, would certainly not think from looking that it should have any reason to think any code was unreachable just based on those definitions but we don't have the full code to be able to see how they're all being used that might fail under static analysis.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!