What is the explanation for “warning: assuming that the loop is not infinite”

前端 未结 3 1195
旧巷少年郎
旧巷少年郎 2021-02-19 09:17

I had just taken the decision to change as many variables from unsigned to int and upon recompiling the code in question, was greeted by this warning m

3条回答
  •  广开言路
    2021-02-19 09:37

    According to this GCC patch from 2005, it appears that GCC is performing an "unsafe loop optimization" (and you are being warned because -funsafe-loop-optimizations is set). If the loop is infinite, this particular optimization will fail somehow.

    Since you said it is a terminating loop, it sounds as though you have nothing to worry about.

    Another relevant part of the patch:

    @opindex Wunsafe-loop-optimizations
    Warn if the loop cannot be optimized because the compiler could not
    assume anything on the bounds of the loop indices.  With
    @option{-funsafe-loop-optimizations} warn if the compiler made
    +such assumptions.
    

提交回复
热议问题