Comment 21 for bug 1722849

Revision history for this message
David Brown (davidbrown) wrote :

I think the -O1 is an interesting detail, but probably not an important one. Certainly if there is no optimisation (-O0), code rarely moves around and the issue does not arrive. The bug in gcc means that the volatile asm /can/ move around - not that it has to be moved. Once it is free to move, the actual code generated will depend on the details of the generated code, and in particular, on the register pressure. These details will vary for different combinations of the code surrounding the problem area, and the optimisation choices. It appears to be just luck that this particular combination of code (and register usage) before the loop, and these particular flags, happens to result in a bad move. Changing apparently irrelevant details in the code also stop the problem appearing - and I expect that if you have enough trials with different code combinations, you will also be able to find examples of the bug with -Os, -O2, -O3, cortex-m4, and other variations of the flags. But you'd need plenty of patience, as combinations that trigger a dangerous move are rare.

This bug has been in gcc for many years, and applies equally to all ports (not just ARM), all variants, and all optimisation levels (except -O0). The fact that no one has noticed it until now shows it is very unlikely to cause a noticeable effect in practice. (Though it may, of course, have caused bugs before without people realising it.) Thanks to Miro for spotting the problem - such rare bugs are always hard to find.