[Bug middle-end/56719] missed optimization: i > 0xffff || i*4 > 0xffff
felix-gcc at fefe dot de
gcc-bugzilla@gcc.gnu.org
Mon Mar 25 15:06:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56719
--- Comment #5 from felix-gcc at fefe dot de 2013-03-25 15:06:02 UTC ---
Yes. However I'd hope that fixing this case would mean that gcc also catches
the case where it is split to multiple if statements.
I think this statement came about because they had a range check and someone
pointed out that checking foo*4>0xffff could be circumvented via an integer
overflow if foo is untrusted and very large.
There are smarter ways to do this but it's not completely mind-bogglingly
incomprehensible why this code would come about.
I have in fact been advocating for a while that programmers should rather spell
out their security checks as plainly as possible and let the compiler optimize
them and remove superfluous checks. See
http://www.fefe.de/source-code-optimization.pdf
if you are interested.
More information about the Gcc-bugs
mailing list