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

Paul Sokolovsky


Previously, there already were examples of the compiler fanciness:

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 | Open source software for ARM SoCs
Follow Linaro:!/linaroorg -

Join to automatically receive all group messages.