This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/64294] invalid code, zero check gets optimized away


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]