Question about -Wstrict-overflow=2

Alexander Motzkau a.motzkau@web.de
Mon Mar 8 21:57:33 GMT 2021


Martin Sebor wrote:
> I think rewriting the test as an equality would be an improvement:
> argptr is incremented by 1 in each iteration so there's no way for
> the pointer to be greater than endbuf.

The example I gave was very simplified. The original function is much more
complex and argptr is advanced by more than 1 in some cases.

But thank you all for your replies. I understand now, where this warning
comes from (I didn't know -fdump-tree-all, that was very interesting):
GCC does loop header duplication, so the condition is duplicated for the
first iteration and that can (and should) be reduced to a constant assuming
pointers don't wrap around (which they shouldn't).

For now I have turned the comparison of pointers into a comparison of
offsets (by subtraction) to silence the warning. But if GCC gets cleverer
I might remove -Wstrict-overflow=2 alltogether.

Thank you very much
Alex


More information about the Gcc-help mailing list