Development is hard if you can't trust your compiler (aka gcc6 did it again)


Paul Sokolovsky
 

Hello,

Previously, there already were examples of the compiler fanciness:
https://lists.zephyrproject.org/pipermail/zephyr-devel/2017-March/007426.html

Here's another one, which is a pure bug. Given code like:

int i;
if (pollnum < NUM_FDS) {
i = pollnum++;
} else {
for (i = 0; pollfds[i].fd >= 0; i++) {
if (i >= NUM_FDS) {
return -1;
}
}
}

i586-zephyr-elf-gcc (gcc 6.2.0), as used for qemu_x86, completely
removes "if" inside the loop. Volatile for i helps and makes it
generate the correct code.

Just checked arm-zephyr-eabi-gcc and it has the same problem (well, the
core generated appears event weirder).

--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog

Join devel@lists.zephyrproject.org to automatically receive all group messages.