Codegen bug - infinite "while" loop generated in place of simple "for" loop

1 ビュー (過去 30 日間)
Dusko Vujadinovic
Dusko Vujadinovic 2022 年 1 月 4 日
回答済み: Sumit Ghosh 2022 年 1 月 10 日
It looks that I encountered the codegen bug. I have a MEX application with multiple entries, i.e. I run the Matlab code as skeleton that calls a few MEX files. For one of them the code apparently ends up in the infinite loop. When I do not run the MEX file for that function (in the coder.runTest() I do not select that function to run as MEX file), so I simply run .m function instead - to code behaves fine.
Also, apparently since the codegen wrongly decides to generate the infinite loop it does not generate any code after that infinite loop. That "for" loop that gets generated as infinite "while" loop is a simple one - one line "printf" (see below). If I simply comment out the loop, the code gets generated, on the first glance it looks OK - but its behaviour is odd, it does not work as from Matlab - yet to debug it in C environment, to provide more details. By the way, for almost 6 months I have been generating the code which was working fine, but suddenly I have plenty of problems. I also encountered other problems where my generated code does not behave as Matlab code, but I am focused right now to only this problem with infinite loop being wrong generated, since that one seems a simple to see.
If this atracts the attention from Matlab supports I am happy to send relevant files.
Matlab "for" loop code:
% why codegen here generates infinite while loop?
for channelNr = 1: numOfTrackedChannels
fprintf('Chan%2u: Nk_ms: %u, codePhase_chips: %4f, pseudoRanges_ms: %4f, fractPseudoRanges_ms: %4f, predictedPseudoranges_ms: %4f, satClockBias_ms: %4f\n',...
uint32(channelNr), uint32(Nk_ms(channelNr)), codePhase_chips(channelNr), pseudoRanges_ms(channelNr), fractionalPseudoRanges_ms(channelNr), predictedPseudoranges_ms(channelNr), satClockBias_ms(channelNr));
end
Generated "while" infinite loop: (
/* why codegen here generates infinite while loop? */
/* 'calcUserPos:58' for channelNr = 1: numOfTrackedChannels */
while (1) {
/* 'calcUserPos:59' fprintf('Chan%2u: Nk_ms: %u, codePhase_chips: %4f, pseudoRanges_ms: %4f, fractPseudoRanges_ms: %4f, predictedPseudoranges_ms: %4f, satClockBias_ms: %4f\n',... */
/* 'calcUserPos:60' uint32(channelNr), uint32(Nk_ms(channelNr)), codePhase_chips(channelNr), pseudoRanges_ms(channelNr), fractionalPseudoRanges_ms(channelNr), predictedPseudoranges_ms(channelNr), satClockBias_ms(channelNr)); */
d0 = muDoubleScalarRound(Nk_ms_data[0]);
if (d0 < 4.294967296E+9) {
if (d0 >= 0.0) {
u2 = (uint32_T)d0;
} else {
u2 = 0U;
}
} else if (d0 >= 4.294967296E+9) {
u2 = MAX_uint32_T;
} else {
u2 = 0U;
}
c_print_processing(u2, codePhase_chips_data[0], pseudoRanges_ms_data[0],
fractionalPseudoRanges_ms_data[0],
predictedPseudoranges_ms, satClockBias_ms_data[0],
&validatedHoleFilling_f2, &validatedHoleFilling_f3,
&validatedHoleFilling_f4, &validatedHoleFilling_f5,
&validatedHoleFilling_f6, &validatedHoleFilling_f7);
mexPrintf("Chan%2u: Nk_ms: %u, codePhase_chips: %4f, pseudoRanges_ms: %4f, fractPseudoRanges_ms: %4f, predictedPseudoranges_ms: %4f, satCl"
"ockBias_ms: %4f\n", 1U, validatedHoleFilling_f2,
validatedHoleFilling_f3, validatedHoleFilling_f4,
validatedHoleFilling_f5, validatedHoleFilling_f6,
validatedHoleFilling_f7);
}
  5 件のコメント
Sumit Ghosh
Sumit Ghosh 2022 年 1 月 10 日
A bug has been created for the development team.
Someone will update this post once some progress is made.

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

採用された回答

Sumit Ghosh
Sumit Ghosh 2022 年 1 月 10 日
This problem is fixed in R2018b and later.
You can try in R2018b or later. If you can't upgrade, please reach out to Technical Support.

その他の回答 (0 件)

製品


リリース

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by