From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17660 invoked by alias); 29 Jul 2009 18:13:02 -0000 Received: (qmail 17575 invoked by uid 48); 29 Jul 2009 18:12:51 -0000 Date: Wed, 29 Jul 2009 18:13:00 -0000 Message-ID: <20090729181251.17574.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c/40907] -O2 generates incorrect code on i386 In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "rguenth at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2009-07/txt/msg02366.txt.bz2 ------- Comment #5 from rguenth at gcc dot gnu dot org 2009-07-29 18:12 ------- long lo_b_2268X; long lo_a_2267X; long lo_c_2271X; ... lo_a_2267X = 65535 & a_1962X; lo_b_2268X = 65535 & b_2266X; ... lo_c_2271X = ((lo_a_2267X) * (lo_b_2268X)); ... if ((536870911 < lo_c_2271X)) { ... else { if ((lo_c_2271X < 0)) { as these are all signed quantities the multiplication in lo_c_2271X = ((lo_a_2267X) * (lo_b_2268X)) if overflowing invokes undefined behavior according to the C language standard. Thus the compiler assumes that multiplying two positive signed values is always positive. Use -fwrapv if you want twos-complement semantics for signed integers. -- rguenth at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|WAITING |RESOLVED Resolution| |INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40907