[Bug rtl-optimization/64294] invalid code, zero check gets optimized away
mikpelinux at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Dec 20 15:24:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64294
--- Comment #10 from Mikael Pettersson <mikpelinux at gmail dot com> ---
You're invoking undefined behaviour due to overflow in signed integer
arithmetic.
Running it after compiling with -fsanitize=undefined produces:
petite.c:391:28: runtime error: signed integer overflow: 2147483647 * 2 cannot
be represented in type 'int'
Fixing that in the following crude way:
--- petite.c 2014-12-20 16:02:59.786063515 +0100
+++ petite-fixed.c 2014-12-20 16:15:05.030889115 +0100
@@ -388,7 +388,7 @@
free(usects);
return 1;
}
- backbytes = backbytes*2 + oob;
+ backbytes = (int)((unsigned
int)backbytes*2 + (unsigned int)oob);
if ( (oob = doubledl(&ssrc,
&mydl, buf, bufsz)) == -1 ) {
free(usects);
return 1;
allows the testcase to work at -O2 and -O3.
More information about the Gcc-bugs
mailing list