In my embedded project, using IAR EWARM dev tools (v7.10.3), I have the following piece of code:
/* 1 */ uint32_t packet_sync = 0;
/* 2 */ uint32_t synced = 0;
/* 3 */ uint32_t gpio = 0;
/* 4 */ while (1) {
/* 5 */ if ((packet_sync != 0) && ((packet_sync = gpio) == 0)) {
/* 6 */ if (synced < 2) {
/* 7 */ synced++;
/* 8 */ }
/* 9 */ }
/* 10 */ };
From some reason, when I compile the code, the compiler gets stuck in the middle of the compilation. I tried playing around with the various constructs, and it seems like any minor change I make, removes the problem (but may make the code incorrect as well). For example, adding a NOP in #6a,and the code does compile successfully:
/* 6 */ if (synced < 2) {
/* 6a */ __NOP();
/* 7 */ synced++;
/* 8 */ }
Other examples of successful changes are removing line #7 or changing line #5 as:
/* 5 */ if ((packet_sync != 0) && ((gpio) == 0)) {
and a couple more variations.
I do not see a C rule violation in the problematic code, and it compiles just fine in Visual Studio 2013. Do I miss something? Why does this code not compile?
* Note: the code presented is an extract of the actual code and is logically meaningless.
Update: The code is compiled with the "High"/"Balanced" optimization level. With lower optimization levels, the compilation concludes just fine.
It also gets stuck when using "High" level but removing the optimization options in the "Enabled transformations:" box. Also, stuck for "Speed" and "Size" options.