This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/64294] invalid code, zero check gets optimized away
- From: "mikpelinux at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 20 Dec 2014 15:24:29 +0000
- Subject: [Bug rtl-optimization/64294] invalid code, zero check gets optimized away
- Auto-submitted: auto-generated
- References: <bug-64294-4 at http dot gcc dot gnu dot org/bugzilla/>
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.